This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Need someone to look at a regression
- To: law at cygnus dot com
- Subject: Re: Need someone to look at a regression
- From: Carlo Wood <carlo at runaway dot xs4all dot nl>
- Date: Fri, 14 Aug 1998 16:40:46 +0200 (CEST)
- Cc: egcs at cygnus dot com (egcs at cygnus dot com)
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>