alinsoar - 8 months ago 36

C Question

In

`6.3 Conversions`

`integer conversion rank`

`precision`

The rank of a signed integer type shall be greater than the rank of any signed integer type with less precision..

After that, it says,

The rank ofshall be greater than the rank of`long long int`

, which shall be greater than the rank of`long int`

, which shall be greater than the rank of`int`

, which shall be greater than ... etc`short int`

So, this is ambiguous. Because the precision of

`int`

`long`

`short`

The precision of INT may either be that one of LONG or SHORT (definition in

`limits.h`

Where is the ambiguity in all this stuff ?

Answer

Generally `long long > long > int > short`

when it comes to precision. Even if that's not the case and they're all the same precision this still means that the rank is `long long > long > int > short`

. The second passage explicitly states that.

`short`

won't ever have a higher rank than `long`

for example. Even if they're the same precision on the platform.

In other words, the precision of the data type can differ from platform to platform (it could be `long long > long > int > short`

but could also be `long long == long == int == short`

), the *rank* of these types is always the same, as specified by the standard : `long long > long > int > short`

.

There is no ambiguity because the first passage:

The rank of a signed integer type shall be greater than the rank of any signed integer type with less precision..

Only says that a type with a higher precision than the other type *must* have a higher rank than the other type.

Then the second passage:

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 ... etc

Is for cases where the platform has 2 different types with equal precision, in this case the standard says that the rank *is always* : `long long > long > int > short`

.

Precision of a type is platform dependent (with the only exception that a type of a higher rank as specified in the standard must have equal or bigger precision than the type with a lower rank). rank of a type is specified by the standard and thus platform independent.