unsigned comparison warning

Hariharan hariharans@picochip.com
Wed Jul 30 19:18: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?

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










More information about the Gcc-help mailing list