开发者

assignment from incompatible pointer type

开发者 https://www.devze.com 2022-12-27 12:14 出处:网络
I have set up the following struct: typedef struct _thread_node_t { pthread_t thread; struct thread_node_t *next;

I have set up the following struct:

typedef struct _thread_node_t {
    pthread_t thread;
    struct thread_node_t *next;
} thread_node_t;

... and then I have defined:

// create thread to for incoming connection
thread_node_t *thread_node = (thread_node_t*) malloc(sizeof(thread_node_t));
pthread_create(&(thread_node->thread), NULL, clie开发者_运维问答nt_thread, &csFD);

thread_node->next = thread_arr; // assignment from incompatible pointer type

thread_arr = thread_node;

where thread_arr is thread_node_t *thread_arr = NULL;

I don't understand why the compiler is complaining. Maybe I'm misunderstanding something.


Shouldn't struct thread_node_t *next; be struct _thread_node_t *next;


Also, do away with the explicit cast.

thread_node_t *thread_node = (thread_node_t*) malloc(sizeof(thread_node_t));

to

thread_node_t *thread_node = malloc(sizeof(thread_node_t));


It's because thread_arr is a thread_node_t pointer, and your next member is a struct thread_node_t pointer. Not the same thing.

0

精彩评论

暂无评论...
验证码 换一张
取 消