Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!bloom-beacon!athena.mit.edu!peter
From: peter@athena.mit.edu (Peter J Desnoyers)
Newsgroups: comp.lang.c
Subject: Re: Variable argument lists.
Message-ID: <5266@bloom-beacon.MIT.EDU>
Date: 11 May 88 17:39:13 GMT
References: <14139@brl-adm.ARPA> <11435@mimsy.UUCP>
Sender: daemon@bloom-beacon.MIT.EDU
Reply-To: peter@athena.mit.edu (Peter J Desnoyers)
Organization: Massachusetts Institute of Technology
Lines: 28

In article <11435@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes:
>In article <14139@brl-adm.ARPA> bates%falcon.dnet%fermat@bru.mayo.edu
>(Cary Bates) writes:
>>In VAX C [by which I presume he means some version of VMS C] there
>>is a macro called va_count.
>I would bet that it does not work.  Try:
>	int f(int x, ...) { return va_count(); }
>	int main() {
>		printf("%d\n", f(0, (double)0, (double)0));
>		return 0;
>	}
>In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
>Domain:	chris@mimsy.umd.edu	Path:	uunet!mimsy!chris

As pointed out, it is VAXC, not VMS C. The VAX explicitly saves a lot
of information on the stack when it makes a subroutine call, and argument
list length is one of them. The issue of arguments of different
lengths is a tricky one - if 'f' pulls arguments off the stack as ints,
then 5 is the correct value, since that is the number it will see. If it
pulls them off as doubles, then the call is incorrect, and va_count might
not be well defined. If it is a printf-like function, then god knows
what happens. (I wish I could check my manual, but I have the 1982 version.)

.
.
.
				Peter Desnoyers
				peter@athena.mit.edu