Need someone to look at a regression

Jeffrey A Law law@cygnus.com
Sat Aug 15 00:17:00 GMT 1998


  In message < 199808141440.QAA29307@jolan.ppro >you write:
  > Hmm, I used to get a warning for this, because the
  > test is always true (unsigned int is always >= 0):
  > 
  > -------------------
  > #include <stdio.h>
  > 
  > int main(int argc, char **argv)
  > {
  >   unsigned int j = argc;
  > 
  >   if (j >= 0)
  >     printf("%u > 0\n", j);
  >   else
  >     printf("%u < 0\n", j);
  > 
  >   return 0;
  > }
Add "-W" and you'll get the desired warning.

  > No warnings?  I am not sure if that is a bug or a feature, but
  > since it is known that (unsigned int) != -1, it just seemed weird
  > that the optimisation chooses to make j == -1 without a warning.
It is valid to compare an unsigned value against -1.

jeff



More information about the Gcc mailing list