In standard C or C ++, int array [0]; is invalid because it does not support arrays with a length of 0. However, some compiler Extensions support arrays with a length of 0.
In C, the 0-length array is mainly used as the last member of the struct, then use it to access a piece of memory after the struct object (usually the dynamically allocated memory ). Due to its non-standard nature, avoid using an array of 0 length in the program. As a replacement, you can use an incomplete array in the C99 standard to replace the array definition with a length of 0. For example:
Struct X {
/* Members */
Int array [];/* Do not write int array [0]; since it is not standard .*/
};
General applications:
Struct {
Int a, B;
Char data [0];
/* Do not write fields below */
};
Struct A * p;
Int n= 100, I;
P = malloc (sizeof (struct A) + n );
For (I = 0; I <n; ++ I)
P-> data [I] = 1;
From redxu's column