Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!husc6!purdue!umd5!mimsy!chris
From: chris@mimsy.UUCP (Chris Torek)
Newsgroups: comp.lang.c
Subject: Re: Variable argument lists.
Message-ID: <11453@mimsy.UUCP>
Date: 12 May 88 07:57:01 GMT
References: <14139@brl-adm.ARPA> <11435@mimsy.UUCP> <5266@bloom-beacon.MIT.EDU>
Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742
Lines: 64

>In article <14139@brl-adm.ARPA> bates%falcon.dnet%fermat@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@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@bloom-beacon.MIT.EDU> peter@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 
    pairs.  Ignoring the  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@mimsy.umd.edu	Path:	uunet!mimsy!chris