From owner-freebsd-chat Fri Feb 1 4:29:36 2002 Delivered-To: freebsd-chat@freebsd.org Received: from falcon.prod.itd.earthlink.net (falcon.mail.pas.earthlink.net [207.217.120.74]) by hub.freebsd.org (Postfix) with ESMTP id A2CC637B443 for ; Fri, 1 Feb 2002 04:29:18 -0800 (PST) Received: from pool0081.cvx40-bradley.dialup.earthlink.net ([216.244.42.81] helo=mindspring.com) by falcon.prod.itd.earthlink.net with esmtp (Exim 3.33 #1) id 16Wcob-0003EF-00; Fri, 01 Feb 2002 04:29:13 -0800 Message-ID: <3C5A8A13.3F6F490F@mindspring.com> Date: Fri, 01 Feb 2002 04:29:07 -0800 From: Terry Lambert X-Mailer: Mozilla 4.7 [en]C-CCK-MCD {Sony} (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: Juha Juntunen Cc: chat@FreeBSD.ORG Subject: ANSI C prototypes in scope References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-chat@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org This isn't a -arch question; moved to -chat, since it's not even really FreeBSD related... Juha Juntunen wrote: > >>>static int sendfile __P((struct printer *pp, int type, char *file, > >>> int format)); > >>> > >>>for a procedure declaration of: > >>> static int > >>> sendfile(pp, type, file, format) > >>> struct printer *pp; > >>> int type; > >>> char *file; > >>> char format; > >>> { > >> > >>That's *EXCATLY* why I'm converting the old, but still legal in c89, > >>style to new style. You get warnings that you didn't get before. > > > >The compiler is broken, if it accepts the second when the > >first prototype is in scope. > > > >It's a broken compiler, period. > > How is the compiler broken, question mark. > > Are you perhaps objecting to the type of the last parameter > ("int format" vs "char format")? Please see Ansi Classic, chapter > "3.5.4.3 Function declarators (including prototypes)", in particular > page 69 lines 19-22. In C99, 6.7.5.3 paragraph #11 seems to apply > similarly. > > If you > - define "__P" suitably > - add "struct printer;" to file scope > - add "}" to complete the function definition > to me, the above code fragment seems to constitute a valid > ANSI C89 translation unit. The compiler complains when the prototype doesn't match the declaration when it is an ANSI style declaration, but not when it is a K&R style declaration (same prototype). Either it should complain for both, or complain for neither. The representational geometry for the function declaration should be irrelevent to whether or not the values match once they are interned. What this is saying is that the compare to the prototype is occuring after the value is interned, and that the value is being interned in K&R form from a K&R declaration. Try switching which one has int and which one char; try adding another chara parameter after the first one. Complainging about prototypes matching functions should work in both directions, sinch "matching" is commutative. It really implies that the compiler could generate incorrect code. I might have a prototype in scope in one place and not another with "char", and the K&R sign extension to int that is resulting in the non-match in this case could result in non-working code on some compiler (perhaps GCC). In any case, the non-match not being caught, even though the declaration is in scope, is really, really ugly. -- Terry To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-chat" in the body of the message