数组的地址是否等于它在 C++ 中的第一个元素的地址? [英] Does the address of the array equal to that of its first element in C++?

查看:32
本文介绍了数组的地址是否等于它在 C++ 中的第一个元素的地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可以在 C 中得到保证,因为 WG14/N1570 中有以下语句:

This can be guaranteed in C because of the following sentence in WG14/N1570:

6.2.5/20 ... 数组类型描述了具有特定成员对象类型(称为元素类型)的连续分配的非空对象集.

6.2.5/20 ... An array type describes a contiguously allocated nonempty set of objects with a particular member object type, called the element type.

但是在WG21/N4527中,即在C++中,对应的语句变成了

But in WG21/N4527, i.e. in C++, the corresponding sentence becomes

8.3.4/1 ...数组类型的对象包含连续分配的 N 个 T 类型子对象的非空集合.

8.3.4/1 ...An object of array type contains a contiguously allocated non-empty set of N subobjects of type T.

而将describes"改为contains",则不能保证数组的地址等于其第一个元素的地址.这种改变是有意的还是无意的?如果是故意的,数组的地址是否等于它在 C++ 中的第一个元素的地址?如果可以,C++标准中哪一段可以保证这一点?

while the word "describes" is changed to "contains", which cannot guarantee that the address of the array equals to that of its first element. Is this change intentional or unintentional? If it is intentional, does the address of the array equal to that of its first element in C++? If it does, which paragraph in the C++ standard can guarantee this?

推荐答案

我不认为它在任何地方明确说明,但我相信它遵循 5.3.3 Sizeof:

I don't think it's stated explicitly anywhere, but I believe it follows from 5.3.3 Sizeof:

n 个元素的数组的大小是一个元素大小的 n 倍

the size of an array of n elements is n times the size of an element

唯一可以存储在数组起始地址的是数组的第一个元素.

that the only thing that can be stored at the array's starting address is the array's first element.

这篇关于数组的地址是否等于它在 C++ 中的第一个元素的地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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