这是我编写的一个结构体。
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’
我对这些错误信息感到困惑。我是否以错误的方式分配了值?
index
中删除=NULL
。您还应该考虑是否需要指针数组(在这种情况下,您将需要分配内存),或者您是否打算声明一个client_t
实例的数组 -static client_t clients[MAXCLIENTS];
。 - simonc