以下代码给出了一个错误,其中定义了{0x30, 700...
。在error: expected '}'
行中,编译器说error: expected ';' at end of declaration
和const struct State {
unsigned int out;
unsigned int time; //10ms units
const struct State *next[16];
};
typedef const struct State SType;
//define your states here e.g. #define stateName 0, etc.
SType FSM[7];
#define goW &FSM[0];
#define go1 &FSM[1];
#define slowW &FSM[2];
#define slow1 &FSM[3];
#define crossW &FSM[4];
#define cross1 &FSM[5];
#define crossB &FSM[6];
//Declare your states here
SType FSM[7] = {
{0x30, 700, {goW, goW, slowW, slowW, slowW, slowW, slowW, slowW, cross1, cross1, slowW, slowW, slowW, slowW, slowW, slowW}},
{0x84, 700, {slow1, slow1, go1, slow1, slow1, slow1, slow1, slow1, slow1, slow1, slow1, slow1, slow1, slow1, slow1, slow1}},
{0x50, 200, {go1, go1, go1, go1, crossW, crossW, crossW, crossW, cross1, cross1, cross1, go1, crossB, crossB, crossB, crossB}},
{0x88, 200, {goW, goW, goW, goW, crossW, crossW, crossW, goW, cross1, cross1, cross1, cross1, crossB, crossB, crossB, goW}},
{0x92, 400, {goW, goW, go1, goW, crossW, goW, go1, go1, cross1, cross1, cross1, cross1, crossB, crossB, crossB, crossB}},
{0x31, 400, {goW, goW, go1, goW, crossW, crossW, crossW, crossW, cross1, cross1, go1, goW, crossB, crossB, crossB, crossB}},
{0x93, 400, {goW, goW, go1, goW, crossW, goW, go1, goW, cross1, cross1, go1, goW, crossB, goW, go1, go1}}
};
根据我们老师的示例代码,这应该有效。但是我在其他地方看到我们应该在结构之外定义“下一个状态”的数组。是这样的吗?
int previous = 0;
int number = 0;
for (int i=1; i < 20; ++i) {
System.out.print(number + " ");
if (i % 2 != 0) {
number = previous + i;
previous = number;
}
else {
number = previous * i;
previous = number;
}
}
答案 0 :(得分:0)
在每个;
之后摆脱#define
。这些不是C语句,也不需要分号。