From owner-freebsd-arch@FreeBSD.ORG Wed Aug 10 01:44:27 2005 Return-Path: X-Original-To: freebsd-arch@freebsd.org Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id EB62816A423 for ; Wed, 10 Aug 2005 01:44:27 +0000 (GMT) (envelope-from rodrigc@crodrigues.org) Received: from rwcrmhc12.comcast.net (rwcrmhc12.comcast.net [216.148.227.85]) by mx1.FreeBSD.org (Postfix) with ESMTP id 169494572D for ; Wed, 10 Aug 2005 00:53:38 +0000 (GMT) (envelope-from rodrigc@crodrigues.org) Received: from c-66-30-115-133.hsd1.ma.comcast.net ([66.30.115.133]) by comcast.net (rwcrmhc12) with ESMTP id <2005081000531701400qhpe5e>; Wed, 10 Aug 2005 00:53:17 +0000 Received: from c-66-30-115-133.hsd1.ma.comcast.net (localhost.127.in-addr.arpa [127.0.0.1]) by c-66-30-115-133.hsd1.ma.comcast.net (8.13.4/8.13.1) with ESMTP id j7A0rNv1047181 for ; Tue, 9 Aug 2005 20:53:24 -0400 (EDT) (envelope-from rodrigc@c-66-30-115-133.hsd1.ma.comcast.net) Received: (from rodrigc@localhost) by c-66-30-115-133.hsd1.ma.comcast.net (8.13.4/8.13.1/Submit) id j7A0rNBc047180 for freebsd-arch@freebsd.org; Tue, 9 Aug 2005 20:53:23 -0400 (EDT) (envelope-from rodrigc) Date: Tue, 9 Aug 2005 20:53:23 -0400 From: Craig Rodrigues To: freebsd-arch@freebsd.org Message-ID: <20050810005323.GA42721@crodrigues.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.9i Subject: [RFC] -Wredundant-decls: keep it or remove it? X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Aug 2005 01:44:28 -0000 Hi, In recent days, while trying to get the kernel in shape to compile with GCC 4.0, I encountered some examples such as the following in net/rtsock.c: extern struct domain routedomain; /* or at least forward */ static struct protosw routesw[] = { { SOCK_RAW, &routedomain, 0, PR_ATOMIC|PR_ADDR, 0, route_output, raw_ctlinput, 0, 0, raw_init, 0, 0, 0, &route_usrreqs } }; static struct domain routedomain = { PF_ROUTE, "route", 0, 0, 0, routesw, &routesw[sizeof(routesw)/sizeof(routesw[0])] }; It is illegal in ISO C to declare a struct as extern (implying external linkage) , and then declare it as static (implying internal linkage). I have two options to fix this. OPTION 1: Change routedomain to not be static: extern struct domain routedomain; .... struct domain routedomain = { ...... } OPTION 2: Forward declare routedomain as static, but remove -Wredundant-decls from kernel makefiles: static struct domain routedomain; .... static struct domain routedomain = { ..... } For OPTION 2, it is necessary to remove -Wredundant-decls because you will get a new compiler warning: warning: redundant redeclaration of 'routedomain' warnig: previous declaration was here ... To fix this problem, is it better to go with OPTION 1 or OPTION 2? I am a bit hesitant to remove -Wredundant-decls from the kernel Makefiles, because it has been there for a long time. Are there cases where the warnings are useful? It seems to warn against legitimate C code in the GCC documentation: `-Wredundant-decls' Warn if anything is declared more than once in the same scope, even in cases where multiple declaration is valid and changes nothing. Any feedback would be appreciated. -- Craig Rodrigues rodrigc@crodrigues.org