【发布时间】:2017-11-18 06:37:00
【问题描述】:
在C中,灵活数组成员的语法如下:
struct s
{
int n;
double d[]; // flexible array member
};
而且,零大小数组在 C 中是非法的。
如果我这样声明数组:
struct s
{
double d[0]; // Zero size array
};
GCC 给出警告:
warning: ISO C forbids zero-size array 'd' [-Wpedantic]
所以,我要回答我的主要问题。
我看到了下面的代码here。
struct squashfs_xattr_entry {
__le16 type;
__le16 size;
char data[0];
};
在 C 中的零大小数组是非法的。
那么,
-
data[0]在结构中声明的目的是什么? -
data[0]在这里做什么?
【问题讨论】:
-
@chux 特别是 GNU GCC 和 Clang。然而,M$VC 拒绝零长度数组。
-
所以你甚至没有在谷歌上搜索过有多少个重复项?!