A structure with a flexible member of an array in another structure

Something like 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 good to me, but I'm a little skeptical that the compiler does not complain if I do this:

struct bar {
    struct foo d;
    int c;
};
+3
source share
1 answer

It is not normal. Section 6.7.2.1 (in No. 1570), paragraph 3 reads

3 (, , ), , ; ( , , , , , ) .

, struct .

( , , .)

+5

All Articles