I made some investigation.
C99 states that the flexible array member is allowed only as last element of a structure. A structure that contains a flexible array member is an "incomplete type" and for this reason has some restrictions:
- could not be included in another structure/union (while a pointer is legal)
- could not be argument of sizeof operator
- could not be statically initialized.
I don't understand the reason of the last restriction. :?
Some compilers (GCC also) have extensions that are not C99 compliant:
- Flexible array members can be declared in any part of a structure, not just as the last member.
- Structures containing flexible array members can be members of other structures.
- Flexible array members can be statically initialized.
I like these extensions, except the first one.
Last, C99 requires that the padding element to align flexible structure member is positioned before it, while many compiler position it after. So this means that an object library could not be compatible with code compiled from a different compiler.
This is not a requirement now.
See
Defect Report #282 - it was added to TC2 for ISO/IEC 9899:1999 so it is in C99 now.
So in my opinion this is not a bug, but could be a feature request.
OK, so let it be a feature request!
![Wink ;)](https://forum.pellesc.de/Smileys/default/wink.gif)
Else I had to rewrite some parts of my library to workaround this.
![Sad :(](https://forum.pellesc.de/Smileys/default/sad.gif)
My feature request is only to support static initialization, not all GCC's extensions.
PS: Thank you very much for investigation and clarification. I think it is not critical for me and others to have this feature implemented, so if it is hard to implement (bug-free of course) - it not worth it.
PPS: What about other
projects? Can some of them be implemented before officially included in C99?
I'm particullary interested in TR 24731: Safer C library functions and TR 24732: Decimal floating point.