【发布时间】:2016-09-07 09:45:01
【问题描述】:
在我的 C 代码中,我有一个 tcpsock.c 和 tcpsock.h 文件。 tpcsock.c 文件包括 tcpsock.h 文件。此套接字代码用于 connmgr.c(包括 tcpsock.c)。 在 C 文件中,我有两个结构体,定义如下:
struct tcpsock{
long cookie;
int sd;
char * ip_addr;
int port;
};
struct conn{
struct tcpsock_t socket;
long last_active;
};
在头文件中我有以下代码:
typedef struct tcpsock tcpsock_t;
typedef struct conn conn_t;
当我尝试编译它时,我收到以下错误:
In file included from connmgr.c:12:0:
lib/tcpsock.c:78:22: error: field ‘socket’ has incomplete type
struct tcpsock_t socket;
^
我一直在到处搜索,但无法找到解决方案,所以我希望这里的任何人都可以帮助我。 提前致谢!
【问题讨论】:
-
如果你typedef
struct tcpsock tcpsock_t,当你声明一个变量为struct tcpsock_t是什么意思?tcpsock_t是您所需要的。 -
你
typedefedtcpsock_t所以把有问题的成员改成tcpsock_t socket;
标签: c struct types incomplete-type