[Bug c/38046] 'warning: comparison between signed and unsigned' shouldn't be given for equality comparisons
--- Comment #4 from manu at gcc dot gnu dot org 2010-02-24 14:29 --- I am really sorry, I don't think we want to add an option for this particular case. As Joseph explained, there is a difference if the variables are mismatched signed/unsigned or not. For your problem, you could use a wrapper around read() that does the cast. Sorry, but this is not worth the overhead. Closing as WONTFIX. -- manu at gcc dot gnu dot org changed: What|Removed |Added CC||manu at gcc dot gnu dot org Status|NEW |RESOLVED Resolution||WONTFIX http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38046
[Bug c/38046] 'warning: comparison between signed and unsigned' shouldn't be given for equality comparisons
--- Comment #3 from edwintorok at gmail dot com 2008-11-07 17:14 --- (In reply to comment #2) 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. It would be nice to have a separate warning option for ==, != comparisons, and another for ,,=,= comparisons. The problem is that with code that uses read(2) and write(2) you get lots of warnings, and adding casts is time-consuming and of little benefit. I'd like to turn -Wsign-compare into -Werror for 'make distcheck' in my project, but can't do that due to the != comparisons. If I would have a distinct -W flag for it, I could -Wno-error that. 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. Ok -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38046
[Bug c/38046] 'warning: comparison between signed and unsigned' shouldn't be given for equality comparisons
--- 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
[Bug c/38046] 'warning: comparison between signed and unsigned' shouldn't be given for equality comparisons
--- Comment #1 from rguenth at gcc dot gnu dot org 2008-11-07 11:26 --- Confirmed. -- rguenth at gcc dot gnu dot org changed: What|Removed |Added Severity|normal |enhancement Status|UNCONFIRMED |NEW Ever Confirmed|0 |1 Keywords||diagnostic Last reconfirmed|-00-00 00:00:00 |2008-11-07 11:26:49 date|| http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38046