c - C 中的指针内部结构错误 "' struct.pointer' '.' 意外“

标签 c pointers gcc struct

得到这个结构:

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/

相关文章:

c++ - 24 位工具栏按钮图像? (WinAPI)

c - 更新c中的动态数组

c - 清理程序时出现段错误

c - 将地址传递给指针函数

c - gcc 为什么以及如何发出 gets() 警告?

java - SWIG CYGWIN DLL 链接

c - 调试 C 代码和指针

c - 如何在 Mac 上使用 C 共享头文件?

c - 函数永远不会执行,但代码会编译

C++ Linux 代码破坏了 Windows 构建,因为缺少 header 意味着函数未定义