user3361731
user3361731

Reputation:

Extern "C" NULL Function Pointer

I've a problem with a libary which is written in C and my own code in C++, the issue seems to be that there is a function pointer which is declared as extern "C" but points to a C++ function (in my case the NULL pointer when I call the function from the libary) that is not declared extern "C".

Now in code:

function_from_lib( ... , (int (*)()) NULL);

Well here you can see that I pass the functionpointer to the function. The issue is that I need a function pointer which aswell points to NULL but the function to which "NULL" points (stupid) should be declared as extern "C". Does anybody know how to solve such an issue or a workaround? I don't have a clue how the function looks inside but it needs a NULL functionpointer for my task.

So if I would have to pass another function like the following:

extern "C" int fkt()
{ 
return NULL;
} 

it would have worked but I need a NULL function pointer.

EDIT:

Well this works:

extern "C" int fkt()
{ 
return NULL;
} 
...

function_from_lib( ... , fkt);

This wouldn't work:

int fkt()
{ 
return NULL;
} 
...

function_from_lib( ... , fkt);

And now I need to pass a NULL functionpointer

function_from_lib( ... , (int (*)()) NULL);

and it doesn't work because it isn't extern "C"

EDIT2 (ERROR UPDATE)

ERROR:
argument of type "I32(*)()" is incompatible with parameter of type "I32(*)() C"

Upvotes: 2

Views: 807

Answers (1)

Lindydancer
Lindydancer

Reputation: 26104

It might be possible to use typedef:s. (I don't have access to a compiler that complains about your code, so I can't verify this). For example:

extern "C"
{
  typedef int (*my_fp_type)(void);
}

function_from_lib(... , (my_fp_type)0);

Upvotes: 2

Related Questions