From owner-freebsd-arch Sun Feb 3 20:57:22 2002 Delivered-To: freebsd-arch@freebsd.org Received: from rwcrmhc53.attbi.com (rwcrmhc53.attbi.com [204.127.198.39]) by hub.freebsd.org (Postfix) with ESMTP id 36A6137B4AD for ; Sun, 3 Feb 2002 20:56:55 -0800 (PST) Received: from peter3.wemm.org ([12.232.27.13]) by rwcrmhc53.attbi.com (InterMail vM.4.01.03.27 201-229-121-127-20010626) with ESMTP id <20020204045654.FMAC10199.rwcrmhc53.attbi.com@peter3.wemm.org> for ; Mon, 4 Feb 2002 04:56:54 +0000 Received: from overcee.wemm.org (overcee.wemm.org [10.0.0.3]) by peter3.wemm.org (8.11.0/8.11.0) with ESMTP id g144uss71742 for ; Sun, 3 Feb 2002 20:56:54 -0800 (PST) (envelope-from peter@wemm.org) Received: from wemm.org (localhost [127.0.0.1]) by overcee.wemm.org (Postfix) with ESMTP id CCDEA3809; Sun, 3 Feb 2002 20:56:53 -0800 (PST) (envelope-from peter@wemm.org) X-Mailer: exmh version 2.5 07/13/2001 with nmh-1.0.4 To: Bruce Evans Cc: Juha Juntunen , arch@FreeBSD.ORG Subject: Re: __P macro question In-Reply-To: <20020202012011.U3304-100000@gamplex.bde.org> Date: Sun, 03 Feb 2002 20:56:53 -0800 From: Peter Wemm Message-Id: <20020204045653.CCDEA3809@overcee.wemm.org> Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Bruce Evans wrote: > On Fri, 1 Feb 2002, 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. > > Right. I don't trust anyone who is not familiar with this point to > globally remove __P. > > People removing __P should also be familiar with the gcc conterpoint: > > void foo(char); /* Wrong; should be "void foo(int);". */ > void foo(c) char c; {} > > gives undefined behaviour in Standard C, but gcc defines its behaviour > to be do-what-naive-programmer-expects. This is only safe provided the > wrong prototype for foo() is always in scope before foo() is called; > otherwise foo() is sometimes passed an int and sometimes a char, but > foo() expects to be passed either an int or a char depending on whether > the wrong prototype is in scope for the function body. There are also variations depending on CPU ABI as well. For the i386 ABI that we use on FreeBSD, a "char" argument (prototyped even) is passed as an "int", always, period. On the Alpha, integral types are passed as 64 bit types. Same on the ia64. I am not sure about sparc64, ppc. Ironically, this means that most of the 'long/int' stuff that upsets people for argument passing on all the 64 bit platforms that I know about, is actually [mostly] harmless. printf("%d %d", (long)i, (long)j) works fine on alpha and ia64, for example.. even though long = 64 bit and int = 32 bit. The bottom line is that using -Wmissing-prototypes and having it compile cleanly is the only safe option that we have. This is doubly important on ansi-fied code as we pass over it. Cheers, -Peter -- Peter Wemm - peter@FreeBSD.org; peter@yahoo-inc.com; peter@netplex.com.au "All of this is for nothing if we don't go to the stars" - JMS/B5 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message