【发布时间】:2019-05-15 10:09:00
【问题描述】:
在使用范围时,我无法让指定的初始化程序语法正常工作。我知道数组可以使用指定的初始化程序,并且我想初始化一个结构数组,以便所有成员在启动时都相同。
编辑:错误是
错误:初始化程序中的数组索引范围超出数组边界 32 |
[0 ... NODELIST_LEN].dev_status = DW_DEV_DISABLED
typedef struct {
int dev_status;
}DW_data;
typedef struct{
DW_data list[NODELIST_LEN];
}DW_nodelist;
我尝试了以下方法:
DW_nodelist dw_list = {
.list[0 ... NODELIST_LEN].dev_status = DW_DEV_DISABLED
}
DW_nodelist dw_list = {
.list = {
[0 ... NODELIST_LEN].dev_status = DW_DEV_DISABLED
}
}
我什至只是为了笑而试了一下:
DW_nodelist dw_list = {
.list = {
.dev_status[0 ... NODELIST_LEN] = DW_DEV_DISABLED
}
}
DW_nodelist dw_list = {
.list = [0 ... NODELIST_LEN].dev_status = DW_DEV_DISABLED
}
我做错了什么,这甚至可以使用结构数组吗?
【问题讨论】:
-
我添加了 gcc 标签,因为此代码不是有效的 C 代码而是 gcc 非标准扩展。