我正在为一个嵌入式系统实验室创建一个有限状态机。编译器(我正在使用ARM的Kiel)抱怨我试图声明一个结构实例数组。我做错了什么?
我的代码(部分):
struct State {
unsigned long OutCars;
unsigned long OutWalk;
unsigned long Time;
unsigned long Next[8];
};
typedef const struct State SType;
SType FSM[11] = {
{0x0C, PF1, 100, {goW, goW, waitW, waitW, waitW, waitW, waitW, waitW} },
{0x14, PF1, 50, {goW, goW, goS, goS, goWa, goWa, goWa, goWa} },
{0x21, PF1, 100, {goS, waitS, goS, waitS, waitS, waitS, waitS, waitS} },
{0x22, PF1, 50, {goS, goW, goS, goW, goWa, goW, goWa, goW} },
{0x24, PF3, 100, {goWa, off1, off1, off1, goWa, off1, off1, off1} },
{0x24, OFF, 50, {on1, on1, on1, on1, on1, on1, on1, on1} },
{0x24, PF1, 50, {off2, off2, off2, off2, off2, off2, off2, off2} },
{0x24, OFF, 50, {on2, on2, on2, on2, on2, on2, on2, on2} },
{0x24, PF1, 50, {off3, off3, off3, off3, off3, off3, off3, off3} },
{0x24, OFF, 50, {on3, on3, on3, on3, on3, on3, on3, on3} },
{0x24, PF1, 50, {goWa, goW, goS, goS, goWa, goW, goS, goS} },
};
错误消息:
...
TableTrafficLight.c(155):错误:#67:应为“}”
{0x0C,PF1,100,{goW,goW,waitW,waitW,waitW,waitW,waitW,waitW,waitW},
...
编辑:原来我的
#define
语句以分号结尾。哎呀。吸取教训。 最佳答案
删除右大括号前的最后一个逗号(删除为突出显示):
SType FSM[11] = {
{0x0C, PF1, 100, {goW, goW, waitW, waitW, waitW, waitW, waitW, waitW} },
{0x14, PF1, 50, {goW, goW, goS, goS, goWa, goWa, goWa, goWa} },
{0x21, PF1, 100, {goS, waitS, goS, waitS, waitS, waitS, waitS, waitS} },
{0x22, PF1, 50, {goS, goW, goS, goW, goWa, goW, goWa, goW} },
{0x24, PF3, 100, {goWa, off1, off1, off1, goWa, off1, off1, off1} },
{0x24, OFF, 50, {on1, on1, on1, on1, on1, on1, on1, on1} },
{0x24, PF1, 50, {off2, off2, off2, off2, off2, off2, off2, off2} },
{0x24, OFF, 50, {on2, on2, on2, on2, on2, on2, on2, on2} },
{0x24, PF1, 50, {off3, off3, off3, off3, off3, off3, off3, off3} },
{0x24, OFF, 50, {on3, on3, on3, on3, on3, on3, on3, on3} },
{0x24, PF1, 50, {goWa, goW, goS, goS, goWa, goW, goS, goS} }, //remove this comma
};
变成:
SType FSM[11] = {
{0x0C, PF1, 100, {goW, goW, waitW, waitW, waitW, waitW, waitW, waitW} },
{0x14, PF1, 50, {goW, goW, goS, goS, goWa, goWa, goWa, goWa} },
{0x21, PF1, 100, {goS, waitS, goS, waitS, waitS, waitS, waitS, waitS} },
{0x22, PF1, 50, {goS, goW, goS, goW, goWa, goW, goWa, goW} },
{0x24, PF3, 100, {goWa, off1, off1, off1, goWa, off1, off1, off1} },
{0x24, OFF, 50, {on1, on1, on1, on1, on1, on1, on1, on1} },
{0x24, PF1, 50, {off2, off2, off2, off2, off2, off2, off2, off2} },
{0x24, OFF, 50, {on2, on2, on2, on2, on2, on2, on2, on2} },
{0x24, PF1, 50, {off3, off3, off3, off3, off3, off3, off3, off3} },
{0x24, OFF, 50, {on3, on3, on3, on3, on3, on3, on3, on3} },
{0x24, PF1, 50, {goWa, goW, goS, goS, goWa, goW, goS, goS} }
};