Path: utzoo!mnetor!uunet!husc6!cmcl2!brl-adm!umd5!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: Variable argument lists. Message-ID: <11435@mimsy.UUCP> Date: 10 May 88 21:34:27 GMT References: <14139@brl-adm.ARPA> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 35 In article <14139@brl-adm.ARPA> bates%falcon.dnet%fermat@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@mimsy.umd.edu Path: uunet!mimsy!chris