与类型转换相关的排名是什么意思? [英] What does rank mean in relation to type conversion?

查看:37
本文介绍了与类型转换相关的排名是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自 C++11 标准(草案 n3337)§5/9:

——如果两个操作数的类型相同,则不再进行转换需要.

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

— 否则,如果两个操作数都具有有符号整数类型或两者都具有无符号整数类型,具有较小整数类型的操作数转换 rank 应转换为操作数的类型更高的排名.

— 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.

— 否则,如果具有无符号整数类型的操作数具有 rank大于或等于另一个操作数类型的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.

——否则,两个操作数都应转换为无符号整数type 对应于带符号整数的操作数的类型输入.

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

在这种情况下排名是什么意思?
当然不是指 std::rank,
因为这与数组中的维数有关......

What does rank mean in this context?
Surely it's not referring to std::rank,
as that has to do with the number of dimensions in an array...

就整数类型和浮点类型而言,我认为是指它们的潜在大小.

In terms of integral types and floating point types, I think it refers to their potential sizes.

C++ 标准保证:

1 == sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long) <=  sizeof(long long)  

我是否正确地假设当时的排名是:

am I right to assume then that the ranks are then:

排名类型
1 char
2
3 int
4 long
5 long long
...

RankType
1 char
2 short
3 int
4 long
5 long long
...

我无法在任何地方找到描述级别的列表每种类型的等级.

I haven't been able to find a list anywhere describing the level of rank for each type.

推荐答案

4.13 节

每个整数类型都有一个整数转换等级,定义如下:

Every integer type has an integer conversion rank defined as follows:

——除了 char 和有符号 char 之外没有两个有符号整数类型(如果 char已签名)应具有相同的等级,即使它们具有相同的等级表示.

— No two signed integer types other than char and signed char (if char is signed) shall have the same rank, even if they have the same representation.

——有符号整数类型的秩应大于任何尺寸较小的有符号整数类型.

— The rank of a signed integer type shall be greater than the rank of any signed integer type with a smaller size.

——long long int 的等级要大于 long 的等级int,应大于 int 的等级,应为大于 short int 的秩,应大于有符号字符的等级.

— 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 the rank of signed char.

——任何无符号整数类型的等级应等于对应的有符号整数类型

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

——任何标准整数类型的秩都应大于秩具有相同大小的任何扩展整数类型.

— The rank of any standard integer type shall be greater than the rank of any extended integer type with the same size.

——char的秩应该等于signed char和unsigned的秩字符.

— The rank of char shall equal the rank of signed char and unsigned char.

— bool 的等级应小于所有其他标准的等级整数类型.

— The rank of bool shall be less than the rank of all other standard integer types.

——char16_t、char32_t 和 wchar_t 的等级应等于等级它们的基础类型 (3.9.1).

— The ranks of char16_t, char32_t, and wchar_t shall equal the ranks of their underlying types (3.9.1).

——任何扩展有符号整数类型相对于另一个的等级具有相同大小的扩展有符号整数类型是实现定义,但仍受制于其他规则确定整数转换等级.

— The rank of any extended signed integer type relative to another extended signed integer type with the same size is implementation-defined, but still subject to the other rules for determining the integer conversion rank.

- 对于所有整数类型 T1、T2 和 T3,如果 T1 的秩大于 T2并且 T2 的排名高于 T3,那么 T1 的排名应该高于T3.

— For all integer types T1, T2, and T3, if T1 has greater rank than T2 and T2 has greater rank than T3, then T1 shall have greater rank than T3.

这篇关于与类型转换相关的排名是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆