|
楼主 |
发表于 2014-5-21 13:51:12
|
显示全部楼层
dr2001 发表于 2014-5-21 12:13
C99/N1256 6.7.2.1-16 flexible array member.
https://gcc.gnu.org/onlinedocs/gcc-4.9.0/gcc/Zero-Lengt ...
谢 了。
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;
In ISO C90, you would have to give contents a length of 1, which means either you waste space or complicate the argument to malloc.
In ISO C99, you would use a flexible array member, which is slightly different in syntax and semantics:
|
|