聚合初始值设定项之外的 C99 指示符成员
C99 designator member outside of aggregate initializer
struct Foo {
char a[10];
int b;
};
static Foo foo = {.a="bla"};
编译以上代码出现以下 gcc 错误:
$ gcc -std=gnu++2a test.cpp
C99 designator ‘a’ outside aggregate initializer
我认为像这样的初始化列表中的 C 字符串指示符在 C++20 中可以吗?我错过了什么?我正在使用 gcc 版本 10.
这是 GCC 的一个已知错误:https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55227
不幸的是,您将不得不要么不使用指定的初始化器,要么为数组使用不同的初始化器:
static Foo foo = {"bla"};
static Foo foo = {.a={'b', 'l', 'a', 0}};
我遇到了同样的错误,我处理了 mv my.cpp my.c
你也可以在这个link中找到答案:
https://pcbartists.com/firmware/esp32-firmware/designator-outside-aggregate-initializer-solved/
#ifdef __cplusplus
extern "C"
{
#endif
// C code goes here
#ifdef __cplusplus
}
#endif
struct Foo {
char a[10];
int b;
};
static Foo foo = {.a="bla"};
编译以上代码出现以下 gcc 错误:
$ gcc -std=gnu++2a test.cpp
C99 designator ‘a’ outside aggregate initializer
我认为像这样的初始化列表中的 C 字符串指示符在 C++20 中可以吗?我错过了什么?我正在使用 gcc 版本 10.
这是 GCC 的一个已知错误:https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55227
不幸的是,您将不得不要么不使用指定的初始化器,要么为数组使用不同的初始化器:
static Foo foo = {"bla"};
static Foo foo = {.a={'b', 'l', 'a', 0}};
我遇到了同样的错误,我处理了 mv my.cpp my.c
你也可以在这个link中找到答案: https://pcbartists.com/firmware/esp32-firmware/designator-outside-aggregate-initializer-solved/
#ifdef __cplusplus
extern "C"
{
#endif
// C code goes here
#ifdef __cplusplus
}
#endif