I am testing a small piece of code with the gcc 4.4.5 and -Wtype-limits .
#include <assert.h>
Then the compiler gives me the following warning:
main.c:7: warning: comparison is always false due to limited range of data type
However, as far as I know, INT_MAX can be equal to +32767 (from C11 (n1570), Β§ 5.2.4.2.1 Dimensions of integer types <limits.h> ). In this case, the variable v will be able to hold the value of INT_MAX+1 , and the expression in assert will be evaluated as 1 .
Therefore, I see two problems:
- GCC takes my architecture into account, because actually
INT_MAX not +32767 . In this case, this will reduce the benefits of -Wtype-limits for me. - This is mistake.
What makes me think about the second option is the following code, which does not give any warnings with the same parameters.
#include <assert.h> #include <limits.h> #include <stdint.h> int main(void) { assert((unsigned int)INT_MAX < (unsigned int)UINT16_MAX); return 0; }
So what is the correct answer?
PS: By the way, I have to apologize for my old version of gcc. The behavior of future releases may be different.
source share