C与C++中Pthread之间的差异

Nau*_*lus 1 c c++ posix pthreads ada

所以我能够使用Ada_function'Address将Ada函数传递给C_function.这是C函数:

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);
}
Run Code Online (Sandbox Code Playgroud)

这非常好.我的问题是当我尝试在C++中使用相同的功能时.它无法编译错误:

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

有没有什么理由可以在C中运行/编译而不是C++?

KII*_*IIV 10

C++中的隐式类型转换比C语言严格得多.该void * function参数不能用作C++或C中的函数指针...

你需要void* (*function)(void*)在你的函数原型中.