簡體   English   中英

pthread_exit() 拋出警告:從不同大小的 integer 轉換為指針 [-Wint-to-pointer-cast] 警告

[英]pthread_exit() throws warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] warning

我一直在學習pthread庫,並創建了一個簡單的代碼來將兩個數字相乘,但是我無法擺脫這個警告。 附言。 代碼工作正常。

#include <stdio.h>
#include <pthread.h>

struct numbers {
   int num1,num2;
};

void *mult(void *param) {
   struct numbers *data = param;
   int res = data->num1 * data->num2;
   pthread_exit((void *)res);
}

int main(){

   pthread_t tid;
   struct  numbers n;
   n.num1 = 2;
   n.num2 = 3;
   pthread_create(&tid, NULL,mult, (void*)&n);
   int res;
   pthread_join(tid, (void *)&res);
   printf("%d\n",(int)res);
   return 0;
}

這是警告:

1.c: In function ‘mult’:
1.c:12:17: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
   12 |    pthread_exit((void *)res);

任何見解將不勝感激。

改變

pthread_exit((void *)res);

pthread_exit((void *)&res);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM