Variable argument lists.

Henry Spencer henry at utzoo.uucp
Fri May 13 02:54:30 AEST 1988


>       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?

Because it's costly and usually unnecessary.  On the VAX it happens to be
free, since the VAX's all-singing-all-dancing-slow-like-turtle function
call instructions give it to you.  Well, they give you a *word* count, not
an argument count, and the difference matters if you start using various
data types, but sloppy programmers ignore that.  On most other machines,
though, the only way to get a count is if the caller carefully provided
you with one.  This can add significantly to the cost of a well-tuned
function-call convention -- and that's not a trivial issue, because C
programs do *lots* of function calls.

>       Without such a feature it seems to me that the most of the 
>       power of the variable argument list is wasted...

Nonsense.  Printf and friends don't need it, because the format string
implicitly contains this information.  Execl and friends don't need it,
because their arg list is null-terminated.  Yes, there are situations
where it would be useful, but not all that many of them.
-- 
NASA is to spaceflight as            |  Henry Spencer @ U of Toronto Zoology
the Post Office is to mail.          | {ihnp4,decvax,uunet!mnetor}!utzoo!henry



More information about the Comp.lang.c mailing list