user289882 user289882 - 2 years ago 458
C Question

Differences between Pthread in C vs C++

So I was able to pass an Ada function using Ada_function'Address to a C_function. Here is the C function:

void Create_Process(int * status, void * function) {
pthread_t new_thread;

//creating function with the given function and no arguments.
*status = pthread_create(&new_thread, NULL, function, NULL);

This worked perfectly fine. My problem is when I try to use this same function in C++. It fails at compiling with the error:

error: invalid conversion from ‘void*’ to ‘void* (*)(void*)’ [-fpermissive]
*status = pthread_create(&new_thread, NULL, function, NULL);

Is there any reason that this works / compiles in C but not C++?

Answer Source

Implicit type conversions in C++ are much more strict than in C. The void * function parameter can't be used as function pointer in C++ or C...

You need void* (*function)(void*) in your function prototype.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download