This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Chill warning questions #2
- To: bothner at cygnus dot com (Per Bothner)
- Subject: Re: Chill warning questions #2
- From: Joe Buck <jbuck at synopsys dot com>
- Date: Wed, 14 Oct 98 17:57:14 PDT
- Cc: egcs at cygnus dot com
> > Why is this warning being issued for != and == comparisons? The
> > reason for this warning is that relational comparisons (<, <=, >, >=)
> > have unexpected results when comparing negative signed values to
> > unsigned values. Since there is no unexpected behavior for != or
> > ==, I don't believe that the compiler should warn in this case.
>
> signed char a = -1;
> unsigned char b = 0xff;
> if (a == b) ...
>
> It certainly seems to me this can be "unexpected". (I don't know what
> the standard says, but I could certainly argue either way!)
This will only surprise those unfamiliar with 2's complement. I don't
think the warning is worth it even in this case.
On the other hand
int i = -1;
unsigned u;
if (i > u)
printf("Welcome to C\n");
is a surprise to a lot of people.