我对两个有符号/无符号整数之间的类型转换感到困惑。为什么有符号和无符号整数具有相同的类型等级?
我搜索了“c++ int type rank”并找到了问题的答案 What does rank mean in relation to type conversion?提到:
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
关于C++ 类型排名(signed/unsigned int 的类型转换),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49128459/