c - C“'struct.pointer''.'中的结构错误中的指针 出乎意料的“
问题描述
得到了这个结构:
typedef struct {
unsigned long index;
void(*function)();
} program;
当我尝试访问第二个字段时,我得到了这个:
error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token in program.callNext = next
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 类型,所以我添加了它
解决方案
当您使用 write typedef struct
program 时,成为结构的名称,而不是实例。只需删除typedef
它就可以了。
推荐阅读
- python - Graphs and Le Chatelier’s Principle
- javascript - 点击后视频无法播放
- firebase - 即使商店中的函数执行良好,Vuex 测试也会抛出错误
- php - 致命错误:未捕获的 PDOException:SQLSTATE [42000]:语法错误或访问冲突:1064 您有错误
- reactjs - 反应力过渡以在悬停时结束
- python - RuntimeWarning:在使用 seaborn 的 python pandas 中的 double_scalars 中遇到无效值
- delphi - REST DataSnap 中的 Content-Type 响应对我不起作用
- php - 比较具有不同扩展名的文件 - 保留更大的文件
- android - java.lang.RuntimeException 尝试从 Intent xssf 工作簿打开 excel 文件时出错
- url - next-translate 显示默认语言