<分区>
引自this site ,
Zero-length arrays are allowed in GNU C. They are very useful as the last element of a structure that is really a header for a variable-length object.
代码:
struct line {
int length;
char contents[0];
};
struct line *thisline = (struct line *)malloc(sizeof (struct line) + this_length);
thisline->length = this_length;
我真的不明白他们的意思:“结构的最后一个元素实际上是可变长度对象的 header ”。有人可以详细说明这句话吗?