Date: Tue, 9 Aug 2005 20:53:23 -0400 From: Craig Rodrigues <rodrigc@crodrigues.org> To: freebsd-arch@freebsd.org Subject: [RFC] -Wredundant-decls: keep it or remove it? Message-ID: <20050810005323.GA42721@crodrigues.org>
next in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050810005323.GA42721>
