passing variable numbers of arguments
Dominick Samperi
samperi at marob.MASA.COM
Mon Jan 9 04:47:52 AEST 1989
In article <15341 at mimsy.UUCP> chris at mimsy.UUCP (Chris Torek) writes:
>[comments about System V style varargs usage...]
It seems that for the ANSI style varargs (that is, the one requiring
stdarg.h), at least one explicitly named arg must be included in the
function definition, so that there is a FIRST that can be supplied to
va_start, as in:
va_list ap ;
va_start(sp, FIRST) ;
...
x = va_arg(ap, TYPE) ;
...
va_end(ap) ;
Is this correct? If not, how does one define a function with a variable
number of args, for which there are no explicitly named args? The standard
documentation on this (K&R Second Edition, for example) does not make
this clear.
It also seems to be the case that it is not possible for a called function
(with a variable number of args) to determine how many args were actually
passed, or when the last arg has been fetched, unless this information is
supplied in the first parameter, say. Wouldn't it have been reasonable for
the standard to specify that the compiler should enable the called function
to determine the number of parameters that were passed, by automatically
passing this information as a first implicit parameter, for example?
Dominick Samperi
samperi at acf8.nyu.edu
uunet!hombre!samperi
More information about the Comp.lang.c
mailing list