Variable argument lists.

Scott Daniels daniels at teklds.TEK.COM
Thu May 12 02:59:48 AEST 1988


In article <12948 at tut.cis.ohio-state.edu> 
		lvc at tut.cis.ohio-state.edu (Lawrence V. Cipriani) writes:
>In article <3569 at ece-csc.UUCP>, jnh at ece-csc.UUCP (Joseph Nathan Hall) writes:
>> 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?
>* 
>* (approx) ...That's because the arguments in your function's argument list 
>* should indicate, either directly with a count, or indirectly (like printf), 
>* how many arguments in the argument list.

VAX(VMS) C gives a count since DEC's call standard requires it.  Every 
procedure call in VMS should follow a standard that includes passing 
information on how many arguments there are.  For most languages, only
a "descriptor" is on the stack (a single word with both type and address
information).  For C, however, values are placed directly on the stack
(which is why a_count is off for big parameters).  Since this count is
supposed to be there for VMS, a handle on it is given to the programmer.
Similarly, since most other language implementers do not need the count,
they don't generate the code to provide it.  This saves code size, 
stack space, and running time (though not too much of any of them).  In
those environments, the cost of providing the a_count would be high: it
would be the cost implementing the count arg for very infrequent use.

Note that DEC has been tempted into violation C conventions by having 
this extra hidden parameter: their fopen works normally only if you
provide two arguments.  If you provide more, it presumes them to be
string specs of filesystem kinds of things.  C, however, requires
that providing too many arguments to a function not bee a problem.  I
wound up quite suprised when my code for an interpretted call that
looked like: ...(*fp)( arg[0], arg[1], arg[2], arg[3], arg[4] )...
access violated (VMS C library dereferenced the NULL following the mode
string).

-Scott Daniels (daniels at teklds.UUCP)



More information about the Comp.lang.c mailing list