微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c – 通过示例的对象和值表示之间的差异

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.

我无法想象为什么它不能说int或long.什么原因?你能澄清一下吗?

解决方法

一个例子可能是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浮动(并且IBM正在移动或已经移入那个方向也是如此).所以没有任何动力继续采用特殊措辞支持他们的标准;最后,在lesat的几年内,C/C++可能会遵循Java路径,并对其所有进行表示基本数据类型.

原文地址:https://www.jb51.cc/c/115823.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐