I tried to convert something from using the struct hack to using a flexible array member, only to run into the following error message:
error: invalid use of structure with flexible array member
(GCC 4.8.1, gnu99, MinGW)
After trying to track down the cause of the message, I distilled it down to the following relatively-minimal case:
struct a {
union {
struct {
int b;
int c[];
} d;
} e;
};
In other words, a struct with a flexible array member doesn't see to be able to be put inside a union in a struct, even if the union is the last member of the struct.
(Note that putting a flexible array member directly inside the union does seem to work.)
Now: is there any good way to work around this besides reverting back to the struct hack (declaring c as an array of length 1)? A pointer to a struct inside the union would work, but suffers an additional layer of indirection.
struct
would make the code valid. I am surprised that it takespedantic
as it's usually used for catching extensions. Does it mean it's OK in gcc land? – Twentyfour