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: Chill warning questions #2



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


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