Variable argument lists.

Chris Torek chris at mimsy.UUCP
Thu May 12 17:57:01 AEST 1988


>In article <14139 at brl-adm.ARPA> bates%falcon.dnet%fermat at bru.mayo.edu
>(Cary Bates) wrote:
>>In VAX C [by which I presume he means some version of VMS C] there
>>is a macro called va_count.

>In article <11435 at mimsy.UUCP> I replied:
>>I would bet that it does not work

(by which I meant that it is probably nargs() in disguise).

In article <5266 at bloom-beacon.MIT.EDU> peter at athena.mit.edu (Peter
J Desnoyers) answers this with:
>As pointed out, it is VAXC, not VMS C.

Calling something `VAX C' or `VAX PASCAL' or `VAX FORTRAN' is a game I
refuse to play.  DEC invented it for the `VAX means VMS; VMS means VAX'
campaign.  While save in the eyes of VMS adherents those years never
really were, they have now been declared over---by Ken Olson no
less---and I think it is about time this bit of doublespeak is smashed
utterly.

>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.

But it is not.  The object stored on the stack is a ten bit field
holding the number of bytes for a `return' instruction to pop.  If the
argument list is more than 1023 bytes long, the number on the stack is
wrong.  (The Berkeley Vax compiler gets this right.  Given

	a() { struct big { int i[1000]; } big; ... f(big); }

the call f(big) compiles to this sequence:

	movc3	$4000,-4000(fp),(sp)
	calls	$232,_f
	addl2	$3072,sp

Note the addl2, which is not redundant even if the second line is
changed to

	calls	$4000,_f

It would take only 128 `double's to go over the 1023 byte limit for
`calls'/`ret'.)

>The issue of arguments of different lengths is a tricky one ....

Indeed it is.  In fact, as I cleverly obscured :-) in my previous
article (>> above), it is the heart of the matter:

[pretend the following paragraph is in boldface]

    C code is never correct if it treats values as typeless.  All
    C expressions and all C variables are represented by <type,value>
    pairs.  Ignoring the <type> part will almost certainly get you in
    trouble.

And this is the problem with va_count(): even if it uses a `hidden
argument' (something other than the return byte count), it can only
tell you how many arguments there were.  It cannot tell you their
types.  In short, it is not general enough for C.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list