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路径,并对其所有进行表示基本数据类型.

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...