...
Prior to the introduction of flexible array members in the C99 standard, structures with a one element array as the final member were used to achieve similar functionality. The following code example illustrates how struct flexArrayStruct
is declared in this case.
...
The approach to acquiring memory in this case is similar to the C99 approach with the exception that 1 is subtracted from array_size
to account for the element present in the structure definition. The problem with using this approach is that the behavior is undefined when accessing other than the first element of data (see Section 6.5.6, Paragraph 8 of the C99 standard). Consequently, the compiler can generate code that does not return the expected value when accessing the second element of data. Structures with flexible array members can be used to produce code with defined behavior. However, some restrictions apply:
...
Wiki Markup |
---|
As described above, the problem with this code is that strictly speaking the only member that is guaranteed to be valid is flexStruct{{flexStruct->data\[0\]}}. Unfortunately, when using compilers that do not support the C99 standard in full, or at all, this approach may be the only solution. Microsoft Visual Studio 2005, for example, does not implement the C99 syntax. |
...