public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* A question about flexible array members
@ 2024-05-19 16:35 Benoît Dufour
  0 siblings, 0 replies; only message in thread
From: Benoît Dufour @ 2024-05-19 16:35 UTC (permalink / raw)
  To: gcc-help

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.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-05-19 16:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-19 16:35 A question about flexible array members Benoît Dufour

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).