gpt4 book ai didi

c++ - 对象和值表示的区别

转载 作者:IT王子 更新时间:2023-10-28 23:39:10 27 4
gpt4 key购买 nike

N3797::3.9/4 [basic.types] :

The object representation of an object of type T is the sequence of N unsigned char objects taken up by the object of type T, where N equals sizeof(T). The value representation of an object is the set of bits that hold the value of type T. For trivially copyable types, the value representation is a set of bits in the object representation that determines a value, which is one discrete element of an implementation-defined set of values

N3797::3.9.1 [basic.fundamental] 说:

For narrow character types, all bits of the object representation participate in the value representation.

考虑以下结构:

struct A
{
char a;
int b;
}

我认为对于 A 并不是对象表示的所有位都参与值表示,因为实现添加了填充。但是其他基本面类型呢?该标准说:N3797::3.9.1 [basic.fundamental]

For narrow character types, all bits of the object representation participate in the value representation. These requirements do not hold for other types.

我无法想象为什么它不适用于 intlong。什么原因?你能澄清一下吗?

最佳答案

一个例子可能是 Unisys 大型机,其中一个 int 有 48位,但只有 40 个参与 值表示(并且 INT_MAX 为 2^39-1);这其他必须为 0。我想任何带有标记的机器架构也会有类似的问题。

编辑:

只是一些进一步的信息:Unisys 大型机是可能是唯一剩下的架构异国情调:Unisys Libra(前 Burroughs)有一个 48 位字,使用有符号整数的大小,并具有标记的架构,其中数据本身包含有关其类型的信息。这Unisys Dorado 是前 Univac:36 位反码(但没有用于标记的保留位)和 9 位字符。

不过,据我了解,Unisys 正在逐步淘汰它们(或已在去年逐步淘汰)支持基于英特尔的系统。一旦它们消失,几乎所有系统都将2 的补码,32 位或 64 位,以及除 IBM 大型机之外的所有将使用 IEEE float 定位(并且 IBM 正在或已经搬入那个方向也是)。所以不会有任何动力继续使用特殊措辞支持它们的标准;最后,在 lesat 的几年内,C/C++ 可能会遵循 Java 路径,并对其所有内容进行表示基本数据类型。

关于c++ - 对象和值表示的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26241397/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com