I used pthread_join function met a problem at yesterday,it's appear complie error, I have search it long time on net, but have no solve it.
pthread_join.c:
#include <stdio.h>
#include <pthread.h>
void* say_hello(void* args)
{
printf("hello from thread\n");
pthread_exit((void*)1);
}
int main()
{
pthread_t tid;
int iRet=pthread_create(&tid,NULL,say_hello,NULL);
if(iRet)
{
printf("pthread create error:iRet=%n\n",iRet);
return iRet;
}
void *retval;
iRet=pthread_join(tid,&retval);
if(iRet)
{
printf("pthread_join error:iRet=%d\n",iRet);
return iRet;
}
printf("retval=%ld\n",(long)**(&retval));
// printf("retval=%ld\n",(long)retval);
return 0;
}
error:
$ error:invalid use of void expression
I try to use (&retval)
to get return value of pthread_join
. I feel the retval belong to void** , then I use (retval) should can get value ,but failed .I'm can't use void to get the values of ** pointer,I guess the retval was been the value by pthread_join,but if use **retval to get it, can't successful.
I used gcc compiled it , it will display:
$ error:invalid use of void expression