gripe: variable arg lists

Henry Spencer henry at utzoo.UUCP
Sun Nov 25 12:25:18 AEST 1984


> ... The secret is a little subroutine that knows where arguments are to be
> found and ... builds a contiguous memory array of them. ... I think
> that with sufficient "cleverness", one can always get away with this
> type of trick.

Does the magic routine parse the printf string to find out how many
arguments there are?  If not, how does it determine this?  Just stuffing
the register arguments "onto the front" of the in-memory arglist is a
machine-dependent trick that won't always work.  And always copying "a
safe number" of in-memory arguments doesn't work, because it assumes
that the arguments are ascending in memory, and that copying extra bytes
won't cause a memory fault or whatever.

In addition, there are some misguided "high-level-language" machines --
the PERQ is an example -- which have a related problem that this trick
doesn't solve.  Such machines *insist* on knowing how big the arglist is
for a given function, have it figuring in the calling sequence to the
point where you can't lie without disaster, and insist that the number
be a constant for each function.  And no, the PERQ doesn't (or at least
didn't, last I heard) have a JSR instruction you could use to build your
own calling sequence.  You get to choose between inefficient argument
passing for all functions (always build an arglist in memory and pass a
pointer to it, rather than passing the args directly), or forgetting
about <varargs.h> and kludging printf et al in machine-dependent ways.
-- 
				Henry Spencer @ U of Toronto Zoology
				{allegra,ihnp4,linus,decvax}!utzoo!henry



More information about the Comp.lang.c mailing list