Search code examples
c++cpthreadsposixada

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++?


Solution

  • 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.