This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Strange sign-compare results
- From: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- To: gcc-bugs at gcc dot gnu dot org, gcc at gcc dot gnu dot org
- Date: Sun, 16 Dec 2001 16:12:06 -0500 (EST)
- Subject: Strange sign-compare results
Given this code:
> int foo(unsigned int u, unsigned int u1, unsigned int u2,
> unsigned short us1, unsigned short us2,
> int i1, int i2, short s1, short s2)
> {
> if (u < (s1-s2))
> return 0;
>
> if (u < (us1-us2))
> return 0;
>
> if (u < (i1-i2))
> return 0;
>
> if (u < (u1-u2))
> return 0;
>
> return 1;
> }
compiling it (on sparc-solaris2) with -Wsign-compare (using 2.95.2,
3.0.3 (pre) or 3.1) yields:
> foo.c:5: warning: comparison between signed and unsigned
> foo.c:8: warning: comparison between signed and unsigned
> foo.c:11: warning: comparison between signed and unsigned
I.e. the last compare of "u < (u1-u2)" doesn't warn. Is this a bug or
feature? Doesn't (u1-u2) become an integer? Please explain. :-)
Thanks,
--Kaveh
--
Kaveh R. Ghazi Engagement Manager / Project Services
ghazi@caip.rutgers.edu Qwest Internet Solutions