From owner-freebsd-chat Sun Feb 9 11:45:29 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.5/8.8.5) id LAA03770 for chat-outgoing; Sun, 9 Feb 1997 11:45:29 -0800 (PST) Received: from nic.follonett.no (nic.follonett.no [194.198.43.10]) by freefall.freebsd.org (8.8.5/8.8.5) with ESMTP id LAA03755 for ; Sun, 9 Feb 1997 11:45:12 -0800 (PST) Received: (from uucp@localhost) by nic.follonett.no (8.8.5/8.8.3) with UUCP id UAA15128; Sun, 9 Feb 1997 20:43:38 +0100 (MET) Received: from oo7 (oo7.dimaga.com [192.0.0.65]) by dimaga.com (8.7.5/8.7.2) with SMTP id UAA03715; Sun, 9 Feb 1997 20:43:52 +0100 (MET) Message-Id: <3.0.32.19970209204352.00aa51d0@dimaga.com> X-Sender: eivind@dimaga.com X-Mailer: Windows Eudora Pro Version 3.0 (32) Date: Sun, 09 Feb 1997 20:43:53 +0100 To: joelh@gnu.ai.mit.edu From: Eivind Eklund Subject: Re: cvs commit: CVSROOT avail Cc: chat@freebsd.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Sender: owner-chat@freebsd.org X-Loop: FreeBSD.org Precedence: bulk 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