C++ 类型排名(signed/unsigned int 的类型转换)

C++ type rank (type conversion for signed/unsigned int)

我对两个 signed/unsigned 整数之间的类型转换感到困惑。为什么有符号和无符号整数具有相同的类型排名?

我搜索了“c++ int type rank”并找到了问题的答案 提到:

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.

但我在 ISO/IEC 14882:2011 中找不到任何关于 signed/unsigned int 类型排名的信息。

ISO/IEC 规范中是否有关于 signed/unsigned int 类型转换的官方说明?

Henri Menke 在 http://eel.is/c++draft/conv.rank 找到了文档,但我在下面包含了相关部分。

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