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

256 views Asked by At

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.

1

There are 1 answers

3
Harry On

change

pthread_exit((void *)res);

to

pthread_exit((void *)&res);