unsigned comparisoms problem?
Andrew Chittenden
andrewch@madge.com
Tue May 12 05:07:00 GMT 1998
The following code is a cut down example of a real program. It compares
unsigned values with <= 0 and yet I don't get a warning. Comparing
with < 0 does give me a warning. I've compiled with -Wall -W. I
cannot find any other option that might give me a warning in this case.
Please can the compiler be enhanced to provide warnings in this case: an
extra option will do if existing functionality shouldn't be broken. There
must be lots of code that would benefit from such a check.
--- begin cut here
#include <stdio.h>
unsigned int bigger = 0x26467b5;
unsigned int smaller = 0x26464f5;
int
f(unsigned int p_smaller, unsigned int p_bigger)
{
int skip = p_smaller - p_bigger;
if ((p_smaller - p_bigger) <= 0) {
printf("smaller %d\n", skip);
} else {
printf("bigger %d\n", skip);
}
if (p_smaller <= 0) {
printf("smaller is -ve\n");
} else {
printf("smaller is +ve\n");
}
return skip;
}
int
main()
{
return f(smaller, bigger);
}
--- end cut here
--
Rgds, Andy Chittenden
Email: achitten@madge.com Fax: +44 1753 661011
Multimedia Development, Madge Networks Ltd
Wexham Springs, Framewood Road, Wexham, Slough SL3 6PJ, England
More information about the Gcc-bugs
mailing list