1
votes

I'm confused about type conversion between two signed/unsigned ints. Why do signed and unsigned integers have the same type rank?

I searched "c++ int type rank" and found and answer to the queston What does rank mean in relation to type conversion? that mentioned:

From C++11 standard (draft n3337) §5/9::

— If both operands have the same type, no further conversion is needed.

— Otherwise, if both operands have signed integer types or both have unsigned integer types, the operand with the type of lesser integer conversion rank shall be converted to the type of the operand with greater rank.

— Otherwise, if the operand that has unsigned integer type has rank greater than or equal to the rank of the type of the other operand, the operand with signed integer type shall be converted to the type of the operand with unsigned integer type.

— Otherwise, if the type of the operand with signed integer type can represent all of the values of the type of the operand with unsigned integer type, the operand with unsigned integer type shall be converted to the type of the operand with signed integer type.

— Otherwise, both operands shall be converted to the unsigned integer type corresponding to the type of the operand with signed integer type.

But I cannot find anything about signed/unsigned int type ranks in ISO/IEC 14882:2011.

Is there an official description for signed/unsigned int type conversion in ISO/IEC Spec?

1
Thanks, Henri. I found it in ISO/IEC 14882:2011 page 88 item 9.jasonxia

1 Answers

0
votes

Henri Menke found the documentation at http://eel.is/c++draft/conv.rank but I have included the relevant sections below.

1.4 The rank of any unsigned integer type shall equal the rank of the corresponding signed integer type.

1.6 The rank of char shall equal the rank of signed char and unsigned