C -使用指定的初始值设定项时删除字段初始值设定项
我正在使用GCC4.6.2(Mingw)并使用C -使用指定的初始值设定项时删除字段初始值设定项,c,gcc,c99,designated-initializer,C,Gcc,C99,Designated Initializer,我正在使用GCC4.6.2(Mingw)并使用-Wextra进行编译。每当我使用指定的初始值设定项时,都会收到奇怪的警告。对于以下代码 typedef struct { int x; int y; } struct1; typedef struct { int x; int y; } struct2; typedef struct { struct1 s1; struct2 s2[4]; } bug_struct; bug_struct bug_struct1 =
-Wextra
进行编译。每当我使用指定的初始值设定项时,都会收到奇怪的警告。对于以下代码
typedef struct
{
int x;
int y;
} struct1;
typedef struct
{
int x;
int y;
} struct2;
typedef struct
{
struct1 s1;
struct2 s2[4];
} bug_struct;
bug_struct bug_struct1 =
{
.s1.x = 1,
.s1.y = 2,
.s2[0].x = 1,
.s2[0].y = 2,
.s2[1].x = 1,
.s2[1].y = 2,
.s2[2].x = 1,
.s2[2].y = 2,
.s2[3].x = 1,
.s2[3].y = 2,
};
我收到警告
bug.c:24:3: warning: missing initializer [-Wmissing-field-initializers]
bug.c:24:3: warning: (near initialization for 'bug_struct1.s1.y') [-Wmissing-field-initializers]
那么到底缺少什么呢?我已经初始化了每个成员。这个警告是不是太直截了当,无法与指定的初始值设定项一起使用,是我做错了什么,还是它是一个编译器错误?正如您所说,这个警告似乎“太直截了当” 此访问模式将每个成员结构作为一个整体初始化,以满足编译器的要求:
bug_struct bug_struct1 =
{
.s1 = {.x = 1, .y = 2},
.s2[0] = {.x = 1, .y = 2},
.s2[1] = {.x = 1, .y = 2},
.s2[2] = {.x = 1, .y = 2},
.s2[3] = {.x = 1, .y = 2}
};
是的,显然没有大括号警告就不能正常工作。我已经在GCC bugzilla中发布了这个;