присвоение от несовместимого типа указателя

Я настроил следующую структуру:

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

... и затем я определил:

// 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, client_thread, &csFD);

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

thread_arr = thread_node;

где thread_arr thread_node_t *thread_arr = NULL;

Я не понимаю, почему компилятор жалуется. Возможно, я неправильно понимаю что-то.

6
задан N 1.1 21 April 2010 в 15:06
поделиться

2 ответа

Не должно struct thread_node_t * next; быть struct _thread_node_t * next;


Кроме того, избавьтесь от явное приведение .

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

-

thread_node_t *thread_node = malloc(sizeof(thread_node_t));
5
ответ дан 16 December 2019 в 21:36
поделиться

Это потому, что thread_arr - указатель thread_node_t, а ваш следующий член - struct указатель thread_node_t. Не то же самое.

3
ответ дан 16 December 2019 в 21:36
поделиться
Другие вопросы по тегам:

Похожие вопросы: