Home >Backend Development >C++ >Are Flexible Array Members Valid in C ?
Flexible Array Members in C
In C99, flexible array members can be used to declare arrays of unknown size as part of a structure. However, the validity of this feature in C has been a subject of confusion.
Validity in C
C was standardized in 1998, predating the introduction of flexible array members in C99. Consequently, flexible array members are not supported in C .
Correct Declaration
Despite the misconception, '[0]' is a valid declaration for a flexible array member in C . This syntax indicates that the size of the array is not specified and must be set by the user at runtime.
Example
In C , the following code will compile and execute without errors:
struct Blah { int foo[0]; };
In contrast, the syntax '[]' without a size is invalid in C . Attempting to declare a flexible array member using this syntax will result in a compiler error.
The above is the detailed content of Are Flexible Array Members Valid in C ?. For more information, please follow other related articles on the PHP Chinese website!