简体   繁体   中英

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

I have been learning about pthread library, and have created a simple code to multiply two numbers, however I'm not able to get rid of this warning. Ps. The code works fine.

#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;
}

Here's the warning:

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);

Any insights would be highly appreciated.

change

pthread_exit((void *)res);

to

pthread_exit((void *)&res);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM