类 /结构的成员的地址订购
C ++ 23草案规定,后来的结构或类的非静态数据成员必须具有更高的地址。 AFAIK较早的标准也需要部分,但是有一些规则,允许编译器重新排序这些数据成员时。谁能告诉我哪些规则完全适用?
The C++23 draft mandates that later non-static data members of a structure or class must have higher addresses. AFAIK earlier standards require this also partitially but there are rules when the compiler is allowed to reorder these data members. Can anyone here tell me which rules apply exactly when ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从最新的C ++ 23草稿中:
非静态成员的分配顺序是该规则的必要结果。该规则是由注释引用的:
在提案P1847之前的C ++ 11-20中,规则是:
C ++ 23的比较,允许编译器重新订购具有不同访问控制的成员。示例:
主要编译器除声明顺序外,实际上还没有使用其他任何内容。
C ++ 03更加放松,尽管巧妙:
From latest C++23 draft:
The allocation order of non-static members is a necessary consequence of this rule. The rule is referred by a note:
In C++11-20, prior to the proposal P1847, the rule was:
Pre C++23, compilers are allowed to re-order members with differing access control. Example:
Major compilers haven't actually used any other than declaration order.
C++03 was even more relaxed, although subtly: