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

标签 c++ c++11 types c++14 rank

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

我搜索了“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/

相关文章:

c++ - static_cast<double> 和 double 一样吗?

haskell - Haskell类型函数?

c - C中头文件中带有struct参数的函数声明

c++ - 如何缩短此方法签名?

c++ - Clang++ 不理解 mac 终端中的 c++11

c++ - 在一个函数中使用 namespace 中的符号,但在同一文件中不使用另一个 namespace 中的符号

c++ - 类型转换 C++ 的行为方式很奇怪

C++ boost : undefined reference to `boost::system::detail::system_category_ncx()`

c++ - tensorflow c++代码SessionFactory::GetFactory如何选择使用哪个 session ?Direct还是Grpc Session?

c++ - QTableView : How can i use clicked() signal correctly to get index of selected item?