0

我一直在学习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);

任何见解将不胜感激。

4

1 回答 1

1

改变

pthread_exit((void *)res);

pthread_exit((void *)&res);
于 2020-11-27T15:29:15.030 回答