Does C99 allow UCHAR_MAX > UINT_MAX
6.3.1.1 States
The rank of a signed integer type shall be greater than the rank of any signed integer type with less precision.
The rank of long long int shall be开发者_C百科 greater than the rank of long int, which shall be greater than the rank of int, which shall be greater than the rank of short int, which shall be greater than the rank of signed char.
So, could this not be the case
signed char has 32 bits (1 padding, 1 sign, 30 precision)
unsigned char has 32 bits (0 padding, 0 sign, 32 precision)
signed int has 32 bits (1 padding, 1 sign, 30 precision)
unsigned int has 32 bits (2 padding, 0 sign, 30 precision)
Just found my own answer. This is not allowed, according to 6.2.5 (8)
For any two integer types with the same signedness and different integer conversion rank (see 6.3.1.1), the range of values of the type with smaller integer conversion rank is a subrange of the values of the other type.
You assumptions about char variables are wrong. In limits.h, CHAR_BIT is 8. You have 32.
In the standard '5.2.4.2.1 Sizes of integer types ' defines CHAR_BIT as 8.
精彩评论