I have a huge C Project. And now i needed a C++ function to fill some variables.
With declaring the function as extern "C", it was no problem, to call the function from the C Project.
The Problem is, that i need to pass a pointer to the C++ function, and in the function, i want to assign a value to the pointer. But exactly at this point, the program crashes with an "Segmentation fault".
Is there a way to make this work? Or is it impossible to work with pointers in this way between C and C++?
Calling the function as thread in C:
Restwo = pthread_create(&num, NULL, (void *) function, &var);
Header
#ifdef __cplusplus
extern "C"
{ // Dies sorgt dafür, dass der Header sowohl in C als auch in C++ funktioniert
#endif
int function(int *pITS);
#ifdef __cplusplus
}
#endif
C++ Function
extern "C" {
int getNewLsaSignals(int *var) {
printf("Successfully started\n"); //works
var = 19; //doesn't work
//insert some c++ code here
}
}