【发布时间】:2010-10-11 21:42:03
【问题描述】:
我有一个头文件 port.h、port.c 和我的 main.c
我收到以下错误:“ports”使用未定义的结构“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 <stdio.h>
#include "port.h"
int main(void)
{
struct port_t ports;
return 0;
}
非常感谢您的任何建议,
【问题讨论】:
-
请注意,一个字符的端口名称不会很令人兴奋!
标签: c struct declaration forward