有?那是因为gcc 为了预先支持C99的这种玩法,所以,让“零长度数组”这种玩法合法了。关于GCC对于这个事的文档在这里:“Arrays of Length Zero”,文档中给了一个例子,完整代码如下:
?
#include
#include
struct line {
? ?int length;
? ?char contents[0]; // C99的玩法是:char contents[]; 没有指定数组长度
};
int main(){
? ? int this_length=10;
? ? struct line *thisline = (struct line *)
? ? ? ? ? ? ? ? ? ? ?malloc (sizeof (struct line) + this_length);
? ? thisline->length = this_length;
? ? memset(thisline->contents, 'a', this_length);
? ? return 0;
}
上面这段代码的意思是:我想分配一个不定长的数组,于是我有一个结构体,其中有两个成员,一个是length,代表数组的长度,一个是contents,代码数组的内容。后面代码里的 this_length(长度是10)代表是想分配的数据的长度。