Tag: 转发

undefined C struct forward声明

我有一个头文件port.h,port.c和我的main.c 我收到以下错误:’ports’使用未定义的struct’port_t’ 我以为我已经在我的.h文件中声明了结构,并且.c文件中的实际结构是可以的。 我需要有前向声明,因为我想在port.c文件中隐藏一些数据。 在我的port.h中,我有以下内容: /* port.h */ struct port_t; port.c: /* port.c */ #include “port.h” struct port_t { unsigned int port_id; char name; }; main.c中: /* main.c */ #include #include “port.h” int main(void) { struct port_t ports; return 0; } 非常感谢任何建议,