Home > front end >  C99 designator member outside of aggregate initializer
C99 designator member outside of aggregate initializer

Time:12-01

struct Foo {
    char a[10];
    int b;
};

static Foo foo = {.a="bla"};

Compiling the above code gives the following gcc error:

$ gcc -std=gnu  2a test.cpp 

C99 designator ‘a’ outside aggregate initializer

I thought that c-string designators in initializer list like these are ok in C 20? What am I missing? I am using gcc version 10.

CodePudding user response:

This is a known bug with GCC: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55227

Unfortunately, you will have to either not use designated initializers or use a different initializer for the array:

static Foo foo = {"bla"};
static Foo foo = {.a={'b', 'l', 'a', 0}};
  • Related