Strange sign-compare results

Kaveh R. Ghazi ghazi@caip.rutgers.edu
Sun Dec 16 13:54:00 GMT 2001


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



More information about the Gcc-bugs mailing list