C " 'struct.pointer.' unexpected " 中结构错误中的指针



得到这个结构:

typedef struct {
unsigned long index;
void(*function)();
} program;

当我尝试访问第二个字段时,我得到这个:

error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token in program.callNext = next

接下来是之前声明的函数:

void next() {
// code
}

编辑:完整代码:

typedef unsigned char bool;
#define true 1
#define false 0 
void next() {
//useless code
}
typedef void(*function)();    
typedef struct {
unsigned long index;
bool running;
function callNext;
} program;
program shell;
shell.running = true;
shell.index = 0;
shell.callNext = next;

GCC 不识别布尔类型,所以我添加了它

当你使用writetypedef struct程序成为结构的名称,而不是实例。只需删除typedef即可。

最新更新