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


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;
}
-------------------

~/tmp>gcc -Wall -pedantic -O2 foo.c
~/tmp>


The following also worries me a bit:

-------------------
#include <stdio.h>

int main()
{
  unsigned int j = -1;

  if (j == -1)
    printf("%u == -1\n", j);
  else
    printf("%u != -1\n", j);

  return 0;
}
-------------------

~/tmp>gcc -Wall -pedantic foo.c
~/tmp>a.out
4294967295 == -1
~/tmp>gcc -Wall -pedantic -O6 foo.c
~/tmp>a.out
4294967295 == -1

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.

-- 
 Carlo Wood  <carlo@runaway.xs4all.nl>


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