C/C++ 中定义的具有灵活数组成员的结构体的用法在哪里?标准?
如果我有这样的代码
struct s { int x; char b[]; };
int main() {
struct s s[10];
}
并使用“gcc -O2 -W -Wall -pedantic”进行编译,那么我得到:
<source>:4:14: warning: invalid use of structure with flexible array member [-Wpedantic]
4 | struct s s[10];
| ^
gcc 是完全正确的。具有灵活数组成员的结构不能这样工作。
C/C++ 标准中的什么地方定义了这个?
If I have code like this
struct s { int x; char b[]; };
int main() {
struct s s[10];
}
and I compile with "gcc -O2 -W -Wall -pedantic" then I get:
<source>:4:14: warning: invalid use of structure with flexible array member [-Wpedantic]
4 | struct s s[10];
| ^
And gcc is totally right. Structs with flexible array members can't work like that.
Where in the C/C++ standards is this defined?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 C 语言中,它是 §6.7.2.1,第 3 段:
正如 @phuclv 在 注释,C++没有这个功能。
In C, it's §6.7.2.1, paragraph 3:
As @phuclv points out in a comment, C++ doesn't have this feature.