------- Comment #2 from joseph at codesourcery dot com 2008-11-07 12:46 ------- Subject: Re: New: 'warning: comparison between signed and unsigned' shouldn't be given for equality comparisons
On Fri, 7 Nov 2008, edwintorok at gmail dot com wrote: > Consider this code: > > int foo(int a, unsigned b) > { > return a != b; > } > $ gcc -O2 -Wall -W foo.c -c > foo.c: In function foo: > foo.c:3: warning: comparison between signed and unsigned integer expressions Seems correct to me. You could have a == -1 and b == UINT_MAX and they would compare equal, but it's not at all obvious from the code that this is the user's intent; and if it is their intent, they can use an explicit cast. > FWIW, if I change int to 'short int' or 'signed char' (and unsigned > appropriately) I get no warning. Both short and unsigned short will be promoted to int before the comparison, so you won't get -1 and USHRT_MAX comparing equal. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38046