所以我能够使用 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);
}
这工作得很好。我的问题是当我尝试在 C++ 中使用相同的函数时。编译失败并出现错误:
error: invalid conversion from ‘void*’ to ‘void* (*)(void*)’ [-fpermissive]
*status = pthread_create(&new_thread, NULL, function, NULL);
有什么理由可以在 C 而不是 C++ 中运行/编译?
最佳答案
C++ 中的隐式类型转换比 C 中严格得多。 void * function
参数不能用作 C++ 或 C 中的函数指针...
您的函数原型(prototype)中需要 void* (*function)(void*)
。
关于c++ - C 与 C++ 中的 Pthread 之间的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38881052/