On Fri, Sep 29, 2006 at 10:55:27AM -0400, Rodolfo Hansen wrote: > [EMAIL PROTECTED] ~ $ gcc -O0 test.c -o test > test.c: In function 'main': > test.c:5: warning: comparison is always false due to limited range of data > type > > > does not make sense to me in the following code: > > > > #include <stdio.h> > int main (char *argv[], int argc) { > unsigned short int number; > > for (number=0; number < ~(number&(~number)) ; number++) { > printf("hello"); > } > > return 0; > }
This question is appropriate for gcc-help mailing list, not here. > i believe gcc is misinterpreting ~(number&(~number)) > > any coments, help welcome. No, please read the C promotion rules. number&(~number) is always 0, ~0 on two's complement arches is -1 (signed int). number < ~(number&(~number)) comparison is done in promoted mode - int, so is (int) number < ~0 which is the same as (int) number < -1. As no value of unsigned short number promoted to int is negative (unless sizeof (int) == sizeof (short)), the compiler correctly warns that the condition is always false. Jakub