本文介绍了“没有更小的数组对象满足这些约束”是什么?意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用于C ++ 17的n4659草案在第4章中描述了该语言的一般原理。在第4.5章C ++对象模型[intro.object]中,我无法理解一个句子的含义(强调我的意思)

The draft n4659 for C++17 describes the general principes of the language in chapter 4. In chapter 4.5, The C++ object model [intro.object], I cannot understand the meaning of one sentence (emphasize mine)

而示例显示数组可以为元素提供更多的存储比数组短:

while examples show that an array can provide storage for elements much shorter than the array:

struct A { unsigned char a[32]; };
struct B { unsigned char b[16]; };
A a;
B *b = new (a.a + 8) B; // a.a provides storage for *b
int *p = new (b->b + 4) int; // b->b provides storage for *p

此处 * p提供存储在16字节数组中仅使用4个字节(假定 sizeof(int)为4)。那么,3.3的含义是什么?

here *p uses only 4 bytes (assuming sizeof(int) is 4) in a 16 bytes array. So, what is the meaning of 3.3?

推荐答案

如果3.3是要区分 a [32]的含义] 来自 b [16] 。前者不提供 * p 的存储空间,因为后者可以。它标识了最小的唯一数组对象,该对象提供了对象所在的存储区域。

The meaning if 3.3 is to differentiate a[32] from b[16]. The former doesn't provide storage for *p because the latter does. It identifies the smallest unique array object that provides the region of storage where the object resides.

如果没有3.3,则定义将是可传递的。 a [32] 将为 * p 提供存储,因为它最终为 b提供了存储[ 16]

Without 3.3 the definition would be transitive. a[32] would provide storage for *p because it ultimately provides storage for b[16].

关于 * p 使用4个字节。重要的是要注意,区域 [b-> b + 4,b-&b; b +8),而存储区是 * p 驻留,不是提供存储的数组对象(该区域根本不是数组对象)。最小的数组对象是 b-> b

Regarding *p using 4 bytes. It's important to note that the region [b->b + 4, b->b +8), while being the storage where *p resides, is not the array object providing the storage (that region isn't an array object at all). That smallest array object would be b->b.

这篇关于“没有更小的数组对象满足这些约束”是什么?意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 21:34