以下声明的目的是什么?
struct test
{
int field1;
int field2[0];
};
Run Code Online (Sandbox Code Playgroud)
那只是一个0长度的数组.根据http://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html:
在GNU C中允许零长度数组.它们作为结构的最后一个元素非常有用,它实际上是一个可变长度对象的头:
struct line {
int length;
char contents[0];
};
struct line *thisline = (struct line *)
malloc (sizeof (struct line) + this_length);
thisline->length = this_length;
Run Code Online (Sandbox Code Playgroud)