[英]accessing a member of a struct via pointer,results in error
This is a struct I have written. 这是我写的结构。
typedef struct {
int index=NULL;
int sd;
pthread_t tid;
char* name;
}client_t;
Next I am making an array of these structs. 接下来我正在制作这些结构的数组。
static client_t *clients[MAXCLIENTS];
Now in the main function, I am assigning values for these structs according to the position in the array. 现在在main函数中,我根据数组中的位置为这些结构赋值。
clients[freeslot]->index=freeslot;
clients[freeslot]->sd=connfd;
clients[freeslot]->tid=syscall(SYS_gettid);
clients[freeslot]->name=threadnames[freeslot];
when i compile, i get these error messages. 当我编译时,我收到这些错误消息。
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’
I am confused about these error messages. 我对这些错误消息感到困惑。 Have I assigned values in a wrong way?
我是否以错误的方式分配了值?
Assignments are not allowed in a struct. 结构中不允许分配。 Try assigning index to NULL outside the struct.
尝试在结构外部将索引分配给NULL。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.