Path: utzoo!attcan!uunet!tektronix!zeus!teklds!daniels From: daniels@teklds.TEK.COM (Scott Daniels) Newsgroups: comp.lang.c Subject: Re: Variable argument lists. Summary: VAX(VMS) C gives a count since DEC's call standard requires it Message-ID: <3080@teklds.TEK.COM> Date: 11 May 88 16:59:48 GMT References: <14139@brl-adm.ARPA> <3569@ece-csc.UUCP> <12948@tut.cis.ohio-state.edu> Reply-To: daniels@teklds.UUCP (Scott Daniels) Followup-To: comp.lang.c Organization: Tektronix, Inc., Beaverton, OR. Lines: 38 In article <12948@tut.cis.ohio-state.edu> lvc@tut.cis.ohio-state.edu (Lawrence V. Cipriani) writes: >In article <3569@ece-csc.UUCP>, jnh@ece-csc.UUCP (Joseph Nathan Hall) writes: >> 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? >* >* (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@teklds.UUCP)