Variable argument lists.
Chris Torek
chris at mimsy.UUCP
Wed May 11 07:34:27 AEST 1988
In article <14139 at brl-adm.ARPA> bates%falcon.dnet%fermat at bru.mayo.edu
(Cary Bates) writes:
>Does anybody know (or care) why in ANSI standard C when
>using a variable length argument list, there is no way to
>determine how many arguments where passed into the function?
Simple: it cannot be done on (some|many|most) architectures.
>In VAX C [by which I presume he means some version of VMS C] there
>is a macro called va_count.
I would bet that it does not work. Try:
int f(int x, ...) { return va_count(); }
int main() {
printf("%d\n", f(0, (double)0, (double)0));
return 0;
}
Chances are the program will print either 5 or 4. Neither is
correct.
>Without such a feature it seems to me that the most of the
>power of the variable argument list is wasted.
Not so. The printf() and exec() families, for instance, can be
implemented without va_count(): the information is found some other
way, by finding `%'s in printf formats and by finding nil pointers in
exec arguments. In particular, printf % formats convey type
information as well; without this, variadic functions that have
variable argument types (as well as or in place of variable number of
arguments) cannot be implemented even *with* va_count.
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain: chris at mimsy.umd.edu Path: uunet!mimsy!chris
More information about the Comp.lang.c
mailing list