This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Relaxing -Wsign-compare



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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]