alinsoar - 1 year ago 75
C Question

# ambiguous definition of `integer conversion rank`

In

`6.3 Conversions`
, the
`integer conversion rank`
for signed integer types is defined as proportional with the
`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 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

So, this is ambiguous. Because the precision of
`int`
can be equal either to the precision of
`long`
or equal to the precision of
`short`
, depending on the implementation of int.

The precision of INT may either be that one of LONG or SHORT (definition in
`limits.h`
). On the other hand it says that rank(INT) < rank (SHORT), even if in limits.h they may be the same.

Where is the ambiguity in all this stuff ?

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download