c++ - 我如何比较 C/C99 规范和 C++ 规范?

标签 c++ c standards specifications c99

我需要验证我可以以某种方式使用 union 。

对于 C99,这个答案就足够了:Union element alignment

C99 - section 6.7.2.1 Structure and union specifiers (paragraph 14):

A pointer to a union object, suitably converted, points to each of its members (or if a member is a bitfield, then to the unit in which it resides), and vice versa.

谁能帮我找到 C++ 的等效保证?

更一般地说,是否有一个很好的来源来查找 C++ 标准的章节/段落引用,这些引用等同于 C 中的已知功能?

非常感谢。

最佳答案

在 C++ (14882:2003) 中,这分为两段:

9.5[class.union]/1

Each data member is allocated as if it were the sole member of a struct.

9.2[class.mem]/17

A pointer to a POD-struct object, suitably converted using a reinterpret_cast, points to its initial member (or if that member is a bit-field, then to the unit in which it resides) and vice versa.

我还没有听说过 C 和 C++ 之间有这样的交叉引用,它可能很重要,正如这个例子所示。

关于c++ - 我如何比较 C/C99 规范和 C++ 规范?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5246389/

相关文章:

c - 错误 : expected declaration specifiers or ‘...’ before string constant while declaring colorbutton in gtk+

c - 读取 fifo 的最后一行

c - 数组验证 - 不使用辅助数组

javascript - 将属性名称隐式传递给对象方法的正确方法是什么?

c++ - 使用带有递归的 std::variant,而不使用 boost::recursive_wrapper

c++ - C++动态数组将每次添加的大小增加1-错误

c++ - 在 C++ 中获取集合的并集、交集或差集

c++ - 错误 :expected unqualified-id before '=' token

c++ - ifstream 的 std::getline 但使用 char* 而不是字符串

403 Forbidden 错误时的浏览器行为