3

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.

    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?

3
  • 1
    Are you sure you're including the correct definition of client_t, i.e. you don't have any more different definions lying around? Commented May 29, 2013 at 16:44
  • 2
    Remove the =NULL from index. You should also consider whether you want an array of pointers (in which case you'll need to allocate memory) or whether you meant to declare an array of client_t instances - static client_t clients[MAXCLIENTS]; Commented May 29, 2013 at 16:47
  • Removed the Null and the problem dissapeared. Thanx Commented May 29, 2013 at 16:50

1 Answer 1

2

Assignments are not allowed in a struct. Try assigning index to NULL outside the struct.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.