我有一个 typdef'd 结构,紧接着在下面我使用 typedef'd 结构同时声明和初始化了我想要的变量。
当我尝试编译代码时,没有与 'hi_aud' 相关的错误消息,但其余结构会显示错误 'error: ";" 预期的'。该数组也提出了这个警告,加上'错误:“}”预期'。
我正在使用 Hi-Tech C compiler v.,它使用 C90 ANSI C 标准。
/* Due to C90, do not change order of vars in struct or else code will explode
*/
typedef struct alarm {
const uint_fast32_t pattern[];
const uint_fast8_t size;
void (*toggle)(void);
void (*off)(void);
bool on;
bool init;
uint_fast8_t pos;
uint_fast16_t start;
uint_fast8_t overflows;
};
static struct alarm hi_aud {
[108, 27, 108, 20, 108, 12, 108, 5],
sizeof(hi_aud.pattern) / sizeof(*hi_aud.pattern),
&sounder_toggle,
&sounder_off,
};
static struct alarm med_aud {
[255, 50, 50, 255],
sizeof(med_aud.pattern) / sizeof(*med_aud.pattern),
&sounder_toggle,
&sounder_off,
};
static struct alarm lo_aud {
[255],
sizeof(lo_aud.pattern) / sizeof(*lo_aud.pattern),
&sounder_toggle,
&sounder_off,
};
static struct alarm hi_vis {
[255],
sizeof(hi_vis.pattern) / sizeof(*hi_vis.pattern),
&hi_vis_toggle,
&hi_vis_off;
};
static struct alarm med_vis {
[255],
sizeof(med_vis.pattern) / sizeof(*med_vis.pattern),
&med_vis_toggle,
&med_vis_off,
};
static struct *alarms = {&hi_aud, &med_aud, &lo_aud, &hi_vis, &lo_vis};
static uint_fast8_t alarms_siz = sizeof(alarms) / sizeof(*alarms);
编辑当我使用'{}'括号初始化数组时,出现另一个错误“错误:声明中没有标识符”。当我使用“[]”括号时,不会发生这种情况。