Path: utzoo!utgpu!watserv1!watmath!att!mcdchg!laidbak!ism.isc.com!uunet!snorkelwacker!apple!motcsd!dms!albaugh From: albaugh@dms.UUCP (Mike Albaugh) Newsgroups: comp.std.c Subject: Reality check (Was Re: prototypes required ?) Message-ID: <1171@dms.UUCP> Date: 19 Oct 90 15:47:52 GMT References: <1061@dg.dg.com> Organization: Atari Games Inc., Milpitas, CA Lines: 59 From article <1061@dg.dg.com>, by lewine@dg-rtp.dg.com (Donald Lewine): > OK. See section 3.7.1: "If a function that accepts a variable number > of arguments is defined without a parameter type list that ends with > the ellipsis notation, the behavior is undefined." I see the word "defined" here, not "declared". That is, it appears to be talking about the file containing the _code_ for printf, rather than the file (stdio.h?) containing a declaration (or possibly a prototype). But I'm not a language lawyer and it's more-or-less irrelevant for reasons outlined below. > This allows the compiler to generate a different calling sequence > for functions with a fixed number of argument and a variable number > of arguments. See section 4.8 in the rationale. It may allow this, if it refered to declaration, but it might not be in an implementor's best interest to take advantage of this "feature". > Well, if the implementation uses one calling sequence (say, with > arguments in registers) for functions with a known number of arguments > and uses a different calling sequence (say, with arguments on the > stack) for functions with a variable number of arguments, the > generated code will not call the library correctly unless the function > is correctly declared. I will admit that you may not get an error > message, but the code will not work! And neither will vast quantities of old code, which are used to "rolling their own" varargs routines. In practice I believe a compiler writer will do as I did (in a re-target of GCC) a) Have the means for detecting "varargsish" stuff, like taking the address of a parameter. b) "forcing" that parameter and any following out of the regs and onto the stack in the "prologue" of the called routine. It is darn hard (not impossible) to "fool" this approach, and not too hard to implement it (I hacked my prologue generation in GCC for a machine with the first five params passed in regs). It is also a whole lot easier on the nerves than explaining to everyone with old code why "my compiler meets the standard nyah, nyah" :-) > Note also that the definition of ANSI C was done to allow a compiler > to generate calls with arguments in registers and several new RISC > compilers take advantage of that. As does my version of gcc, but it takes steps to avoid blowing up on really common old idioms. Mike BTW: to those who are interested, no, the obvious hooks for this do _not_ work (on 1.37), but it _can_ be done with less obvious hooks and version 2 is supposed to make it easier. That is not, however a subject for comp.std.c. | Mike Albaugh (albaugh@dms.UUCP || {...decwrl!pyramid!}weitek!dms!albaugh) | Atari Games Corp (Arcade Games, no relation to the makers of the ST) | 675 Sycamore Dr. Milpitas, CA 95035 voice: (408)434-1709 | The opinions expressed are my own (Boy, are they ever)