得到这个结构:
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 无法识别 bool 类型,所以我添加了它
最佳答案
当您使用编写typedef struct
程序时,将成为结构的名称,而不是实例。只需删除 typedef
即可工作。
关于c - C 中的指针内部结构错误 "' struct.pointer' '.' 意外“,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52544133/