Elite Mx
Elite Mx

Reputation: 133

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 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)

Upvotes: 3

Views: 453

Answers (2)

jim mcnamara
jim mcnamara

Reputation: 16399

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.

Upvotes: 0

Elite Mx
Elite Mx

Reputation: 133

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.

Upvotes: 5

Related Questions