varargs vs. stdargs

Doug Gwyn gwyn at smoke.BRL.MIL
Wed Nov 15 01:36:27 AEST 1989


In article <GNB.89Nov14103800 at baby.bby.oz> gnb at bby.oz (Gregory N. Bond) writes:
>Is there some method of specifying varadic functions that is portable
>to both old (varargs) and new (stdargs) implementations?

The simple answer is that at some level you have to switch on __STDC__.

>Is there an ANSI prototype for old varargs functions?

No, such functions were not legal C although they happened to work in
most implementations.  Because of the widespread use of printf() in
applications, it behooved implementors to figure out some solution.

>Or do I have two prototyes and two implementations surrounded by
>#if __STDC__?

Some people use macros to make this a bit less painful, but in any
event in the definition of the body of a variadic function you have
to pick up the "fixed" arguments via va_arg() for varargs, but
they're already accessible under stdarg.



More information about the Comp.std.c mailing list