Reputation: 1760
What is the advantage of using zero-length arrays in C?
Eg:
struct email {
time_t send_date;
int flags;
int length;
char body[];
}list[0];
Upvotes: 2
Views: 238
Reputation: 145899
An array of size 0
is not valid in C.
char bla[0]; // invalid C code
From the Standard:
(C99, 6.7.5.2p1) "If the expression is a constant expression, it shall have a value greater than zero."
So list
declaration is not valid in your program.
An array with an incomplete type as the last member of a structure is a flexible array member.
struct email {
time_t send_date;
int flags;
int length;
char body[];
};
Here body
is a flexible array member.
Upvotes: 4
Reputation: 5526
Here is your answer: http://www.quora.com/C-programming-language/What-is-the-advantage-of-using-zero-length-arrays-in-C
Upvotes: -1