Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!henry From: henry@utzoo.UUCP (Henry Spencer) Newsgroups: net.lang.c Subject: Re: gripe: variable arg lists Message-ID: <4676@utzoo.UUCP> Date: Sat, 24-Nov-84 21:25:18 EST Article-I.D.: utzoo.4676 Posted: Sat Nov 24 21:25:18 1984 Date-Received: Sat, 24-Nov-84 21:25:18 EST References: <348@gitpyr.UUCP> <3106@alice.UUCP> <394@ucsfcgl.UUCP>, <1254@utah-gr.UUCP> Organization: U of Toronto Zoology Lines: 27 > ... 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 and kludging printf et al in machine-dependent ways. -- Henry Spencer @ U of Toronto Zoology {allegra,ihnp4,linus,decvax}!utzoo!henry