Follow up to How Do I Prototype this?

Stephen Clamage steve at taumet.com
Wed Jul 4 01:45:49 AEST 1990


In article <351 at demott.COM> kdq at demott.COM (Kevin D. Quitt) writes:
>    BTW, my compiler accepts:
>int foo( int, ... );
>    but  rejects:
>int foo(...);
>    and calls the ... a syntax error.  Anyone: is the above declaration
>ANSI, or K&R, or none of the above?

Your compiler is correct.  ANSI C requires at least one parameter
declaration to precede the ellipsis (...).  It also requires the
ellipsis notation in the prototype and definition of any function
which takes a variable number of arguments (in a conforming program).
Of course, the ellipsis must occur at the end of the parameter list.

This is covered in the syntax section of 3.5.4 of the ANSI standard,
and elaborated in 3.5.4.3.  The feature interacts with the typedef
and macros in standard header <stdarg.h>, in section 4.8.

This means that there is no portable way to declare and use a function
which may take zero or more arguments, or whose first argument might be
of any type.

How does one write a function which might or might not have a first
argument of any type?  However you do it, I suspect the program
would be very difficult to understand and maintain.  Some re-thinking
of the program design would be in order.
-- 

Steve Clamage, TauMetric Corp, steve at taumet.com



More information about the Comp.lang.c mailing list