unsigned comparison warning

Hariharan hariharans@picochip.com
Tue Jul 29 11:35:00 GMT 2008


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? 

Cheers
Hari









More information about the Gcc mailing list