unsigned comparison warning

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,
I found something rather strange with the unsigned comparison warnings in GCC.

If i had,

unsigned char a;



int foo ()

{

if (a >= 0)

return 0;

else

return 1;

}

and i did gcc -O2 -c trial.c, then i get a warning

trial.c:6: warning: comparison is always true due to limited range of data type

It works the same way if i used an unsigned short. But, if i use unsigned int/long, i dont get this warning. This is on x86. Is there an explanation for this?

I had initially tried this with 4.1.1 (default on RHE5), but Ian mentioned that the behaviour is the same on mainline with -Wextra.

Cheers
Hari









[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux