【问题标题】:Field has incomplete type error字段有不完整的类型错误
【发布时间】: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 是您所需要的。
  • typedefed tcpsock_t 所以把有问题的成员改成tcpsock_t socket;

标签: c struct types incomplete-type


【解决方案1】:

typedef struct tcpsock tcpsock_t;tcpsock_t 定义为struct tcpsock。因此,您的结构定义必须如下所示:

struct conn{
   tcpsock_t socket;
   long last_active;
};

【讨论】:

  • @Tibo 不客气。我认为您可以将这个问题标记为已解决;-)
猜你喜欢
  • 2012-09-10
  • 2011-04-29
  • 1970-01-01
  • 1970-01-01
  • 2018-05-11
  • 2012-05-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多