Chill warning questions #2

Joe Buck jbuck@synopsys.com
Wed Oct 14 18:58:00 GMT 1998


> > 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.



More information about the Gcc mailing list