() obsoleted?!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Zeljko Vrba

    #1

    () obsoleted?!

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: RIPEMD160

    Can somebody explain why the () function argument list with the semantics
    "any number of arguments of any type" has been obsoleted in C99? Is there a
    suitable replacements with the same semantics (something like: void f(...))?

    This was a _very_ useful thing (although, rarely, but it was). It is used
    in some parts of POSIX, e.g. the makecontext function (which is also now
    obsoleted because of C99). With the suggestion "use threads" instead of
    *context functions. Nonsense! For example, look at my coroutine library for
    C: http://www.core-dump.com.hr/index.pl?node_id=422

    It makes extensive use of these functions. And can somebody find an
    _efficient_ way to translate this into threads?!

    Bah, I could just rewrite it to use GNU Pth, it has functions similar
    to *context, but with no () declarators.

    I was _very_ dissapointed to see this feature removed in C99. In the next
    std. they'll probably declare implicit void* conversion obsolete too.. Those
    two things are among the 3 things[1] That made possible to use C as a
    dynamic typeless language. Now one of them is gone.

    [1] The 3rd being the struct address guarantee, i.e. the address of a struct
    equals the address of its first member.

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.0.6 (GNU/Linux)
    Comment: For info see http://www.gnupg.org

    iD8DBQFCR6ihFto fFpCIfhMRA1mIAK CH46kLdH7T8/DDCEVfOCPv8GdBu gCfVDiJ
    3RRmUh70zn+h3Fq x5gQX5Mw=
    =02ho
    -----END PGP SIGNATURE-----
  • Martijn

    #2
    Re: () obsoleted?!

    > Can somebody explain why the () function argument list with the[color=blue]
    > semantics "any number of arguments of any type" has been obsoleted in
    > C99? Is there a suitable replacements with the same semantics
    > (something like: void f(...))?[/color]

    Yes, you can use ellipses ( ... ) to indicate an unknown amount of arguments
    (being zero or more), but this requires at least one known argument, so
    something like this (prototype):

    int f(int i, ...);

    Then you use the va_ set of macros to extract the arguments. Note that some
    types are converted to others and you need to have some way of knowing which
    types of arguments to expect (and the compiler won't check this for you!)
    You also need to include stdarg.h .

    All further information is easily acquired using google.

    Good luck,

    --
    Martijn



    Comment

    • Zeljko Vrba

      #3
      Re: () obsoleted?!

      -----BEGIN PGP SIGNED MESSAGE-----
      Hash: RIPEMD160

      In article <4247b89c$0$143 $e4fe514c@news. xs4all.nl>, Martijn wrote:[color=blue]
      >
      > Then you use the va_ set of macros to extract the arguments. Note that some
      >[/color]
      Not exactly what I'm having in mind. I had the situation like this (when
      writing a language interpreter).

      void interpret(void)
      {
      void (*op)();

      while(1) {
      /* fetch opcode and initialize op based on it */
      op(arg1, arg2, ...);
      }
      }

      Then each of the called-by-op functions had their real definition like:

      void op1(int);
      void op2(int, int);
      void op3(int, double);
      etc.

      the interpreter loop is always calling via the pointer with correct number and
      types of arguments.

      In this case I didn't have to mess around with va_ macros, and everything
      was 'cleaner'... Now the () feature is obsoleted in C99 with nothing to
      replace it in future version of the standard...


      -----BEGIN PGP SIGNATURE-----
      Version: GnuPG v1.0.6 (GNU/Linux)
      Comment: For info see http://www.gnupg.org

      iD8DBQFCR7voFto fFpCIfhMRA28BAJ 94me9BORWDHCv3J ZJi1z966bbDcQCf dRBQ
      9cTfIdh86oFWB5C Fsi7Q8Ts=
      =gqFm
      -----END PGP SIGNATURE-----

      Comment

      • Robert Bachmann

        #4
        Re: () obsoleted?!

        Zeljko Vrba wrote:[color=blue]
        > Can somebody explain why the () function argument list with the semantics
        > "any number of arguments of any type" has been obsoleted in C99? Is there a
        > suitable replacements with the same semantics (something like: void f(...))?[/color]

        AFAIK void f(...); wasn't a valid declaration in C89 either.
        See http://www.eskimo.com/~scs/C-faq/q15.9.html:

        | Question 15.9
        |
        | My compiler isn't letting me declare a function
        |
        | int f(...)
        | {
        | }
        | i.e. with no fixed arguments.
        |
        | Standard C requires at least one fixed argument,
        | in part so that you can hand it to va_start.
        |
        | References: ANSI Sec. 3.5.4, Sec. 3.5.4.3, Sec. 4.8.1.1
        | ISO Sec. 6.5.4, Sec. 6.5.4.3, Sec. 7.8.1.1


        --
        Robert Bachmann <news@rbach.pri v.at>, PGP-Key ID: 0x8994A748

        Comment

        • pjp@plauger.com

          #5
          Re: () obsoleted?!

          >> Can somebody explain why the () function argument list with the
          semantics
          "any number of arguments of any type" has been obsoleted in C99?

          [pjp] No. I just looked at the C99 Standard and it appears to still be
          there. IIRC, the only thing that went away in this area was the ability
          to call a function that had not been declared.

          P.J. Plauger
          Dinkumware, Ltd.


          Comment

          • Andrey Tarasevich

            #6
            Re: () obsoleted?!

            Zeljko Vrba wrote:[color=blue]
            > ...
            > In this case I didn't have to mess around with va_ macros, and everything
            > was 'cleaner'... Now the () feature is obsoleted in C99 with nothing to
            > replace it in future version of the standard...
            > ...[/color]

            What exactly do you mean by this? C99 refers to non-prototype function
            declarations as an "obsolescen t feature". C89/90 refers to this feature
            in exactly the same way. Nothing changed in this respect from C89/90 to
            C99. Yet you are complaining about some change in C99. What change are
            you talking about?

            --
            Best regards,
            Andrey Tarasevich

            Comment

            • Zeljko Vrba

              #7
              Re: () obsoleted?!

              -----BEGIN PGP SIGNED MESSAGE-----
              Hash: RIPEMD160

              In article <1112010684.373 410.221930@g14g 2000cwa.googleg roups.com>, pjp@plauger.com wrote:[color=blue]
              >
              > [pjp] No. I just looked at the C99 Standard and it appears to still be
              > there. IIRC, the only thing that went away in this area was the ability
              > to call a function that had not been declared.
              >[/color]
              Look at the following link:


              And quotes from the rationale:

              "With the incorporation of the ISO/IEC 9899:1999 standard into this
              specification it was found that the ISO C standard (Subclause 6.11.6)
              specifies that the use of function declarators with empty parentheses is
              an obsolescent feature."

              "There is no way in the ISO C standard to specify a non-obsolescent function
              prototype indicating that a function will be called with an arbitrary number
              (including zero) of arguments of arbitrary types (including integers, pointers
              to data, pointers to functions, and composite types)."

              While it did not go away, it is marked obsoleted. That was my only original
              claim. Which this paragraph expresses puts more succintly and clearly. And
              the question, of course, remains: why it was obsoleted?


              -----BEGIN PGP SIGNATURE-----
              Version: GnuPG v1.0.6 (GNU/Linux)
              Comment: For info see http://www.gnupg.org

              iD8DBQFCSSQ0Fto fFpCIfhMRA2+GAJ wMj0DwQRM9hNHug izHYO8H5v1EugCf SPOe
              ET2BQuGErCWehdX wYpC3k/M=
              =3wvW
              -----END PGP SIGNATURE-----

              Comment

              • Keith Thompson

                #8
                Re: () obsoleted?!

                Zeljko Vrba <first.last@oss .unist.hr> writes:[color=blue]
                > In article <1112010684.373 410.221930@g14g 2000cwa.googleg roups.com>,
                > pjp@plauger.com wrote:[color=green]
                >>
                >> [pjp] No. I just looked at the C99 Standard and it appears to still be
                >> there. IIRC, the only thing that went away in this area was the ability
                >> to call a function that had not been declared.
                >>[/color]
                > Look at the following link:
                > http://www.opengroup.org/onlinepubs/...kecontext.html
                >
                > And quotes from the rationale:
                >
                > "With the incorporation of the ISO/IEC 9899:1999 standard into this
                > specification it was found that the ISO C standard (Subclause 6.11.6)
                > specifies that the use of function declarators with empty parentheses is
                > an obsolescent feature."
                >
                > "There is no way in the ISO C standard to specify a non-obsolescent
                > function prototype indicating that a function will be called with an
                > arbitrary number (including zero) of arguments of arbitrary types
                > (including integers, pointers to data, pointers to functions, and
                > composite types)."
                >
                > While it did not go away, it is marked obsoleted. That was my only original
                > claim. Which this paragraph expresses puts more succintly and clearly. And
                > the question, of course, remains: why it was obsoleted?[/color]

                "Obsolescen t" does not been obsolete. It merely means that it could
                (not necessarily that it will) become obsolete in a future standard.

                C90 6.9.4 says:

                The use of function declarators with empty parentheses (not
                prototype-format parameter type declarators) is an obsolescent
                feature.

                C99 6.11.6 says exactly the same thing:

                The use of function declarators with empty parentheses (not
                prototype-format parameter type declarators) is an obsolescent
                feature.

                The feature is still fully supported by the C90 and C99 standards.

                --
                Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
                We must do something. This is something. Therefore, we must do this.

                Comment

                • CBFalconer

                  #9
                  Re: () obsoleted?!

                  Zeljko Vrba wrote:[color=blue]
                  >[/color]
                  .... snip ...[color=blue]
                  >
                  > And quotes from the rationale:
                  >[/color]
                  .... snip ...[color=blue]
                  >
                  > "There is no way in the ISO C standard to specify a non-obsolescent
                  > function prototype indicating that a function will be called with
                  > an arbitrary number (including zero) of arguments of arbitrary
                  > types (including integers, pointers to data, pointers to functions,
                  > and composite types)."
                  >
                  > While it did not go away, it is marked obsoleted. That was my only
                  > original claim. Which this paragraph expresses puts more succintly
                  > and clearly. And the question, of course, remains: why it was
                  > obsoleted?[/color]

                  Because it is a security risk and doesn't prevent writing any
                  correct code. You always have varargs and its insecurities
                  available. It should be obvious that the requirement for one known
                  parameter is not a bind, since such is necessary to transfer
                  information about any further parameters in all cases.

                  --
                  "If you want to post a followup via groups.google.c om, don't use
                  the broken "Reply" link at the bottom of the article. Click on
                  "show options" at the top of the article, then click on the
                  "Reply" at the bottom of the article headers." - Keith Thompson


                  Comment

                  • Andrey Tarasevich

                    #10
                    Re: () obsoleted?!

                    Zeljko Vrba wrote:[color=blue][color=green]
                    >>[/color]
                    > Look at the following link:
                    > http://www.opengroup.org/onlinepubs/...kecontext.html
                    >
                    > And quotes from the rationale:
                    >
                    > "With the incorporation of the ISO/IEC 9899:1999 standard into this
                    > specification it was found that the ISO C standard (Subclause 6.11.6)
                    > specifies that the use of function declarators with empty parentheses is
                    > an obsolescent feature."[/color]

                    I don't know why ISO/IEC 9899:1999 is mentioned there. As it was said
                    before, this type of declaration was referred to as "obsolescen t" in the
                    C89/90 standard as well. Nothing really changed in C99. Apparently,
                    authors of the above document didn't know this fact. Instead of taking a
                    minute to verify it they jumped to conclusion that this was a new
                    addition to C99.
                    [color=blue]
                    > That was my only original
                    > claim. Which this paragraph expresses puts more succintly and clearly. And
                    > the question, of course, remains: why it was obsoleted?[/color]

                    It probably become obsolescent "in transition" from K&R to C89/90 as
                    something that falls into the same family as K&R-style function
                    definitions (which are also obsolescent).

                    --
                    Best regards,
                    Andrey Tarasevich

                    Comment

                    • Peter Nilsson

                      #11
                      Re: () obsoleted?!

                      CBFalconer wrote:[color=blue]
                      > Zeljko Vrba wrote:[color=green]
                      > > Re: () obsoleted?!
                      > >
                      > > While it did not go away, it is marked obsoleted. That was my
                      > > only original claim. Which this paragraph expresses puts more
                      > > succintly and clearly. And the question, of course, remains:
                      > > why it was obsoleted?[/color]
                      >
                      > Because it is a security risk and doesn't prevent writing any
                      > correct code. You always have varargs and its insecurities
                      > available. It should be obvious that the requirement for one
                      > known parameter is not a bind, since such is necessary to
                      > transfer information about any further parameters in all cases.[/color]

                      Hmmm...

                      I wouldn't say in _all_ cases. One has to ask why function macros
                      can be declared identifier(...) in C99, but functions can't.

                      C++ allows (...) functions as a 'catch all'.

                      It's not beyond possibility that C programmers have occasionally
                      wished for such a facility to be available in C. Of course, C
                      doesn't have function overloading, so the need is considerably
                      less.

                      But that doesn't mean the requirement for one known parameter in
                      variadic functions is ("obviously" ) _never_ a bind. (IMO)

                      --
                      Peter

                      Comment

                      • CBFalconer

                        #12
                        Re: () obsoleted?!

                        Peter Nilsson wrote:[color=blue]
                        >[/color]
                        .... snip ...[color=blue]
                        >
                        > But that doesn't mean the requirement for one known parameter in
                        > variadic functions is ("obviously" ) _never_ a bind. (IMO)[/color]

                        Because you have to be able to transmit something in order to
                        describe how many things are being transmitted. It's not a bind
                        because it is absolutely necessary.

                        --
                        "If you want to post a followup via groups.google.c om, don't use
                        the broken "Reply" link at the bottom of the article. Click on
                        "show options" at the top of the article, then click on the
                        "Reply" at the bottom of the article headers." - Keith Thompson


                        Comment

                        • Peter Nilsson

                          #13
                          Re: () obsoleted?!

                          CBFalconer wrote:[color=blue]
                          > Peter Nilsson wrote:[color=green]
                          > >[/color]
                          > ... snip ...[color=green]
                          > >
                          > > But that doesn't mean the requirement for one known parameter
                          > > in variadic functions is ("obviously" ) _never_ a bind. (IMO)[/color]
                          >
                          > Because you have to be able to transmit something in order to
                          > describe how many things are being transmitted.[/color]

                          What if the function wants to ignore all the parameters and
                          do nothing?
                          [color=blue]
                          > It's not a bind because it is absolutely necessary.[/color]

                          Why?

                          [The discussion (snipped above) is why the standard says
                          it is necessary for functions. It isn't necessary for
                          function macros in C99.]

                          --
                          Peter

                          Comment

                          • Ben Pfaff

                            #14
                            Re: () obsoleted?!

                            CBFalconer <cbfalconer@yah oo.com> writes:
                            [color=blue]
                            > Peter Nilsson wrote:[color=green]
                            >> But that doesn't mean the requirement for one known parameter in
                            >> variadic functions is ("obviously" ) _never_ a bind. (IMO)[/color]
                            >
                            > Because you have to be able to transmit something in order to
                            > describe how many things are being transmitted. It's not a bind
                            > because it is absolutely necessary.[/color]

                            It is not absolutely necessary, e.g. I can pass a null-terminated
                            list of pointers.
                            --
                            "Some programming practices beg for errors;
                            this one is like calling an 800 number
                            and having errors delivered to your door."
                            --Steve McConnell

                            Comment

                            • Arthur J. O'Dwyer

                              #15
                              Re: () obsoleted?!


                              On Tue, 29 Mar 2005, Ben Pfaff wrote:[color=blue]
                              > CBFalconer <cbfalconer@yah oo.com> writes:[color=green]
                              >> Peter Nilsson wrote:[color=darkred]
                              >>> But that doesn't mean the requirement for one known parameter in
                              >>> variadic functions is ("obviously" ) _never_ a bind. (IMO)[/color]
                              >>
                              >> Because you have to be able to transmit something in order to
                              >> describe how many things are being transmitted. It's not a bind
                              >> because it is absolutely necessary.[/color]
                              >
                              > It is not absolutely necessary, e.g. I can pass a null-terminated
                              > list of pointers.[/color]

                              Even a null-terminated list has to contain at least one element (namely,
                              a null pointer). I agree with CBFalconer in practice, but with the other
                              side in theory; certainly there's nothing intrinsically /wrong/ with

                              void foo(...) {
                              /* ignore all arguments and */ return;
                              }

                              or even [UNTESTED PSEUDO-C]

                              int bar_type;
                              int bar(...) {
                              va_list ap;
                              va_start(ap);
                              switch (bar_type) { /* set by the user before this call */
                              case 0: printf("%d", va_arg(ap, int)); break;
                              case 1: printf("%s", va_arg(ap, const char*)); break;
                              case 2: printf("%g", va_arg(ap, double)); break;
                              }
                              va_end(ap);
                              return bar_type;
                              }

                              The standard just arbitrarily disallows such constructions. I think
                              the restriction has absolutely no effect on /real-world/ programs, but
                              it is kind of weird and non-orthogonal, if you ask me.

                              my $.02,
                              -Arthur

                              Comment

                              Working...