c - Dereferencing ‘void *’ pointer and cast doesn't work -


i try project using multi-threading not familiar void * , how use it. have problem in function :

void *find_way_out(void *tree) {   int    i;   t_tree *tmp;   t_tree **road;   int    j;   int    th_nbr;    th_nbr  = tree->thread_nbr;   j       = 0;   road    = xmalloc(sizeof(t_tree));         = 0;   tmp     = (t_tree *)tree;   road[j] = tmp;    tmp->visited[th_nbr] = 1;    while (1)   {     while (tmp->leaf[i] != null)     {       printf("room : %s && room next %s\n", tmp->room, tmp->leaf[i]->room);       if (tmp->leaf[i]->visited[th_nbr] == 0)       {         road[++j]            = tmp;         tmp                  = tmp->leaf[i];         tmp->visited[th_nbr] = 1;                            = -1;         printf("going room-> %s\n", tmp->room);       }        if (tmp->type == end)       {         printf("find end...\n");         pthread_exit(&j);       }       i++;     }       tmp = road[j];       if (--j == -1)         pthread_exit(0);       = 0;       printf("backing room %s\n", tmp->room);   }   pthread_exit(0); } 

the error @ line : th_nbr = tree->thread_nbr;

thread_nbr integer in structure tree.

when compile have these errors :

sources/find_way.c:21:16: warning: dereferencing ‘void *’ pointer    th_nbr = tree->thread_nbr;                 ^ sources/find_way.c:21:16: error: request member ‘thread_nbr’ in not structure or union 

you have idea fix it? thanks.

in case, @ time of dereferencing,

 th_nbr = tree->thread_nbr; 

tree of type void *.

you need move

 tmp = (t_tree *)tree; 

before

th_nbr = tmp->thread_nbr;   //tree changed tmp 

so that, @ point of dereferencing, tmp should pointer of type tree.


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -