Is something like the code below valid?
struct foo {
int a;
int b[];
};
struct bar {
int c;
struct foo d;
};
struct bar *x = malloc(sizeof(struct bar) + sizeof(int [128]));
It seems ok to me, but I am a bit skeptical because compiler does not complain if I do:
struct bar {
struct foo d;
int c;
};
It’s not okay. Section 6.7.2.1 (in n1570), point 3 says
So a
structwith a flexible array member may not be part of another struct.(It may well work as the last member of a struct, though, if the compiler accepts it.)