Date: Sun, 09 Feb 1997 20:43:53 +0100 From: Eivind Eklund <eivind@dimaga.com> To: joelh@gnu.ai.mit.edu Cc: chat@freebsd.org Subject: Re: cvs commit: CVSROOT avail Message-ID: <3.0.32.19970209204352.00aa51d0@dimaga.com>
next in thread | raw e-mail | index | archive | help
At 02:13 PM 2/9/97 -0500, Joel Ray Holveck wrote: >>>Is this incorrect? >>No, it is correct. However, unless everybody is _very_ careful, it is >>likely that we end up with some functions being defined somewhere their >>prototype is not in scope. This can cause weirdness. > >Not with you. I thought that an ANSI definition acted precisely as a >K&R definition and an ANSI declaration if the function has not been >declared, and K&R definition with checking against the prototype if >it has, so an ANSI definition will emit the same code as a K&R >definition. The only time we get wierdness is when a function is >*called* with its prototype being out of scope. I believe there can be different argument promotions, resulting in a different stack frame for functions without prototypes in scope. There are four cases here (I'll use a simple void(short,long) on a hypothetical byte-based machine with 32-bit ints and 16-bit shorts as an example): (K&R and K&R) The function is defined without a prototype in scope, and used without a prototype in scope. offsetof(short) == 0, offsetof(long) == 4. (K&R and ANSI) The function is defined without a prototype in scope, and used with a prototype in scope. Offset for function: short 0, long 4. Offset for call: short 0, long 2. (ANSI and K&R) The function is defined with a prototype in scope, and used without a prototype in scope. Offset for function: short 0, long 2. Offset for call: short 0, long 4. (ANSI and ANSI) The function is defined with a prototype in scope, and used with a prototype in scope. Offsets: short 0, long 4. As you can see, the function need to correspond with it's usage. All K&R calls will widen their arguments to int size - ANSI calls do not need to do this. (Looking it up to check that what I've written is actually correct) Section 6.3.2.2 and 6.4.5.3 of the ISO standard (Use 3 instead of 6 to get references to the ANSI standard or the rationale.) Eivind Eklund perhaps@yes.no http://maybe.yes.no/perhaps/ eivind@freebsd.org
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3.0.32.19970209204352.00aa51d0>