main.cpp: In function ‘bool foo()’:
main.cpp:6: warning: comparison is always false due to limited range of data type
1 #include <stdio.h> 2 bool foo() 3 { 4 short nCommand = 0x813a; 5 //return nCommand == (short)0x813a; 6 return nCommand == 0x813a; 7 #if 0 8 if ( nCommand == (short)0x813a ) { 9 return true; 10 } else { 11 return false; 12 } 13 #endif 14 } 15 int main(int argc, const char *argv[]) 16 { 17 18 if (foo()){ 19 printf("TRUE\n"); 20 } else { 21 printf("FALSE\n"); 22 } 23 return 0; 24 }
看来要比较short整是要小心点..不然错了也很难找....