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]

Re: Need someone to look at a regression



  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


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