...
Wiki Markup |
---|
The problem with this code is that the only member that is guaranteed to be valid, by strict C99 definition, is {{structP->data\[0\]}}. Consequently, for all {{i > 0}}, the results of the assignment are undefined. |
Implementation Details
GNU C uses zero-length arrays for flexible array members.
...
bgColor | #FFcccc |
---|
...
The non-compliant example may be the only alternative for compilers that do not yet implement the C99 syntax. Microsoft Visual Studio does not implement the C99 syntax.
Compliant Solution
This compliant solution uses the flexible array member to achieve a dynamically sized structure.
...