我已经设置了以下结构体:
struct:
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;
我不明白为什么编译器在抱怨。也许我理解错了什么。
thread_node_t *thread_node = malloc(sizeof *thread_node);
。 - Steve Jessopmalloc
的结果进行强制转换,但是其中一个影响因素是,正如你所说,如果省略强制转换,它将无法编译为C ++。我认为这是不强制转换的一个很好的理由! - Steve Jessop