Consider this code: int foo(int a, unsigned b) { return a != b; }
int bar(int a, unsigned b) { return (unsigned)a != b; } int foobar(int a, unsigned b) { return a != (int)b; } $ gcc -O2 -Wall -W foo.c -c foo.c: In function foo: foo.c:3: warning: comparison between signed and unsigned integer expressions The generated code is identical for all 3 functions, so there is no reason to "fix" the warning in the code. Rather I think gcc shouldn't warn in this case at all. A more realistic example: #include <unistd.h> int foo(int fd, char *buf, size_t n) { return (read(fd, buf, n) != n); } FWIW, if I change int to 'short int' or 'signed char' (and unsigned appropriately) I get no warning. -- Summary: 'warning: comparison between signed and unsigned' shouldn't be given for equality comparisons Product: gcc Version: 4.3.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: edwintorok at gmail dot com GCC build triplet: x86_64-linux-gnu GCC host triplet: x86_64-linux-gnu GCC target triplet: x86_64-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38046