作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在使用 GCC 4.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 =
{
.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}
};
关于c - -Wmissing-field-initializer 使用指定的初始值设定项时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22194935/
我想成为 Spark 纱客户(link)。是否需要安装hadoop?还是只安装 yarn 可以吗? (by this link) 最佳答案 No Spark不需要Hadoop即可运行。 Apache
我是一名优秀的程序员,十分优秀!