cast problem pthreads

  • Thread starter =?ISO-8859-1?Q?Andreas_M=FCller?=
  • Start date
?

=?ISO-8859-1?Q?Andreas_M=FCller?=

my problem is probably simple to fix but I don't now how,
i have a thread function

void *display(struct Camera *camera)

and i try to create that thread via

pthread_create(&draw_thread, NULL, display, &camera);

when I compile with gcc it works,
using g++ there is an error:
invalid conversion from `void*(*)(Camera*)' to ` void*(*)(void*)'

where is the problem?
 
M

Max M.

Andreas said:
void *display(struct Camera *camera)

and i try to create that thread via

pthread_create(&draw_thread, NULL, display, &camera);

when I compile with gcc it works,
using g++ there is an error:
invalid conversion from `void*(*)(Camera*)' to ` void*(*)(void*)'

where is the problem?

The problem is that pthread_create expects an argument of type

void*(*)(void*)

while you provided one of type

void*(*)(Camera*)


Solution: change display's signature so as for it to match pthread_create's
requirements, and cast the argument back to Camera * in the function's body.

Max
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,241
Latest member
Lisa1997

Latest Threads

Top