Cで長さゼロの配列を使用する利点は何ですか?
例えば:
struct email {
time_t send_date;
int flags;
int length;
char body[];
}list[0];
サイズの配列は0
C では無効です。
char bla[0]; // invalid C code
標準から:
(C99, 6.7.5.2p1) 「式が定数式である場合、ゼロより大きい値を持たなければならない。」
したがって、list
宣言はプログラムでは無効です。
構造体の最後のメンバーとして不完全な型を持つ配列は、柔軟な配列メンバーです。
struct email {
time_t send_date;
int flags;
int length;
char body[];
};
これbody
は柔軟な配列メンバーです。
これがあなたの答えです:http://www.quora.com/C-programming-language/What-is-the-advantage-of-using-zero-length-arrays-in-C