实例和值表示之间的区别 [英] Difference between object and value representation by example

查看:104
本文介绍了实例和值表示之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

类型为T的对象的对象表示形式是N的序列 T类型的对象占用的无符号char对象,其中N等于 sizeof(T).对象的值表示形式是一组位 包含类型T的值.对于平凡可复制的类型,该值 表示是对象表示中的一组位, 确定一个值,该值是 实施定义的一组值

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]

I think for A not all bits of the object representation participate in the value representation because of padding added by implementation. But what about others fundamentals type? The Standard says: 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不成立.什么原因?你能澄清一下吗?

I can't imagine why it doesn't hold for say int or long. What's the reason? Could you clarify?

推荐答案

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

An example might be the Unisys mainframes, where an int has 48 bits, but only 40 participate in the value representation (and INT_MAX is 2^39-1); the others must be 0. I imagine that any machine with a tagged architecture would have similar issues.

请提供一些进一步的信息:Unisys大型机是 可能仅有的剩下的真正的架构 异国情调:Unisys天秤座(前Burroughs)有一个48位字,使用带符号 整数的幅度,并具有标记的架构,其中 数据本身包含有关其类型的信息.这 Unisys Dorado是Univac的前任产品:36位用户的补充产品(但没有 保留位以供标记)和9位字符.

Just some further information: the Unisys mainframes are probably the only remaining architectures which are really exotic: the Unisys Libra (ex-Burroughs) have a 48 bit word, use signed magnitude for integers, and have a tagged architecture, where the data itself contains information concerning its type. The Unisys Dorado are the ex-Univac: 36 bit one's complement (but no reserved bits for tagging) and 9 bit char's.

据我了解,Unisys正在逐步淘汰它们(或 已在去年淘汰了它们),而支持基于Intel的产品 系统.一旦消失,几乎所有系统都将成为 2的补码,32或64位以及IBM大型机以外的所有主机 将使用IEEE浮动poing(并且IBM正在搬入或搬入 那个方向).所以不会有任何动机 继续用特殊措辞支持他们的标准; 最后,在lesat的几年中,C/C ++可能 遵循Java路径,并在其所有路径上加上一个表示形式 基本数据类型.

From what I understand, however, Unisys is phasing them out (or has phased them out in the last year) in favor of Intel based systems. Once they disappear, pretty much all systems will be 2's complement, 32 or 64 bits, and all but the IBM mainframes will use IEEE floating poing (and IBM is moving or has moved in that direction as well). So there won't be any motivation for the standard to continue with special wording to support them; in the end, in a couple of years at lesat, C/C++ could probably follow the Java path, and impose a representation on all of its basic data types.

这篇关于实例和值表示之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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