What is the purpose of the following declaration?
struct test
{
int field1;
int field2[0];
};
That's simply a 0 length array. According to http://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html:
Zero-length arrays are allowed in GNU C. They are very useful as the last element of a structure which 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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With