[RFC] -Wredundant-decls: keep it or remove it?
From: Craig Rodrigues (rodrigc_at_crodrigues.org)
Date: 08/10/05
- Previous message: Colin Percival: "Re: /usr/portsnap vs. /var/db/portsnap"
- Next in thread: David O'Brien: "Re: [RFC] -Wredundant-decls: keep it or remove it?"
- Reply: David O'Brien: "Re: [RFC] -Wredundant-decls: keep it or remove it?"
- Reply: Bruce Evans: "Re: [RFC] -Wredundant-decls: keep it or remove it?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 9 Aug 2005 20:53:23 -0400 To: freebsd-arch@freebsd.org
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 _______________________________________________ freebsd-arch@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-arch To unsubscribe, send any mail to "freebsd-arch-unsubscribe@freebsd.org"
- Previous message: Colin Percival: "Re: /usr/portsnap vs. /var/db/portsnap"
- Next in thread: David O'Brien: "Re: [RFC] -Wredundant-decls: keep it or remove it?"
- Reply: David O'Brien: "Re: [RFC] -Wredundant-decls: keep it or remove it?"
- Reply: Bruce Evans: "Re: [RFC] -Wredundant-decls: keep it or remove it?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|