Newsgroups: comp.lang.c Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: Variable length argument list handling Message-ID: <1989Aug18.185706.26936@utzoo.uucp> Organization: U of Toronto Zoology References: <1441@esunix.UUCP> Date: Fri, 18 Aug 89 18:57:06 GMT In article <1441@esunix.UUCP> bjones@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@zoo.toronto.edu