Relaxing -Wsign-compare
Morten Welinder
terra@diku.dk
Thu Sep 20 08:45:00 GMT 2001
IMHO, the -Wsign-compare is a bit too agressive to be really useful.
Consider this example:
-----------------------------------------------------------------------------
struct {
int a, b;
} foo [] = {
{1,2}, {3,4}
};
int
main (int argc, char **argv)
{
int i;
for (i = 0; i < sizeof (foo) / sizeof (foo[0]); i++)
;
return 0;
}
-----------------------------------------------------------------------------
> gcc-3.0 -Wsign-compare signed.c
signed.c: In function `main':
signed.c:12: warning: comparison between signed and unsigned
A similar warning can be had with typical MIN and MAX macros when
used with an unsigned expression and an explicit integer, say
MAX (expr, 42).
Would it be reasonable to silence this warning when one of the sides is
a constant (in the C meaning) that fits well within the range of the
other side's type?
Morten
More information about the Gcc
mailing list