Variable length argument list handling

Henry Spencer henry at utzoo.uucp
Sat Aug 19 04:57:06 AEST 1989


In article <1441 at esunix.UUCP> bjones at esunix.UUCP (Ben Jones) writes:
>Question:  Why can't a C function which allows a  variable  number  of
>arguments find out how many arguments were actually passed?

Historically, because on many machines there is no way for the callee
to figure this out without the caller explicitly passing an invisible
parameter.  Such parameters are expensive when every function call has
to include one.

Nowadays the efficiency impact could be mitigated somewhat by doing it
only for varargs functions, since ANSI C requires the varargsness of
a function to be known at the call site.

>It may be possible to fake a "va_count" on those  processors.   Sun  3
>has  an  instruction following the function call which pops the stack.
>Sun 4 and MIPS do not pop the stack but they  consistently  store  the
>last  actual  parameter  in  the instruction preceeding the call...

A lot of this is very dependent on the details of the compiler, and is
not guaranteed by the architecture.  To say nothing of what happens when
you start doing inter-language calls.  Don't forget that instruction space
may not be readable at all for an ordinary program.

It doesn't seem to be useful enough to be worth the trouble.
-- 
V7 /bin/mail source: 554 lines.|     Henry Spencer at U of Toronto Zoology
1989 X.400 specs: 2200+ pages. | uunet!attcan!utzoo!henry henry at zoo.toronto.edu



More information about the Comp.lang.c mailing list