A question about flexible array members
Benoît Dufour
benoit.dufour@mail.com
Sun May 19 16:35:11 GMT 2024
Hello,
I've a little question about the GCC extension that allows to put
Flexible Array Members at the end of a struct in the C language.
So basically I can do this:
typedef struct IntArray {
int x;
int Data[];
} IntArray;
IntArray array = (IntArray) {0, {1, 2, 3, 4, 5}};
And the generated Assembly code will be:
array:
.long 0
.long 1
.long 2
.long 3
.long 4
.long 5
But why can't I do this?
typedef struct IntArray {
struct {};
int Data[];
} IntArray;
IntArray array = (IntArray) {{}, {1, 2, 3, 4, 5}};
What I would want is that all the elements of the array be stored in
the Data member, and not have an extra x member in the struct.
More information about the Gcc-help
mailing list