【发布时间】:2013-05-25 01:07:37
【问题描述】:
这是我写的结构体。
typedef struct {
int index=NULL;
int sd;
pthread_t tid;
char* name;
}client_t;
接下来我将制作这些结构的数组。
static client_t *clients[MAXCLIENTS];
现在在主函数中,我根据数组中的位置为这些结构分配值。
clients[freeslot]->index=freeslot;
clients[freeslot]->sd=connfd;
clients[freeslot]->tid=syscall(SYS_gettid);
clients[freeslot]->name=threadnames[freeslot];
当我编译时,我收到这些错误消息。
code.c:185:12: error: ‘client_t’ has no member named ‘index’
code.c:186:19: error: ‘client_t’ has no member named ‘sd’
code.c:187:19: error: ‘client_t’ has no member named ‘tid’
code.c:188:19: error: ‘client_t’ has no member named ‘name’
我对这些错误消息感到困惑。我是否以错误的方式赋值?
【问题讨论】:
-
您确定您包含正确的 client_t 定义,即您没有其他不同的定义吗?
-
从
index中删除=NULL。您还应该考虑是否需要一个指针数组(在这种情况下,您需要分配内存)或者您是否打算声明一个client_t实例数组 -static client_t clients[MAXCLIENTS]; -
删除了 Null 并且问题消失了。谢谢
标签: c pointers error-handling struct