I have this C function that simply calls back another function passed as a parameter
void call_my_function(void (*callback_function)())
{
callback_function();
}
This is C test code:
void func_to_call() // a simple test function passed in as a callback
{
printf("function correctly called");
}
void test() // entry point
{
void (*foo)();
foo = &func_to_call;
call_my_function(foo); // pass the address of "func_to_call()" to "call_my_function()"
}
Essentially, from test()
, I call call_my_function()
passing in the address of func_to_call()
, and then call_my_function()
calls back func_to_call()
.
From swift I see correctly the functions test()
and func_to_call()
, but it seems that
void call_my_function(void (*callback_function)())
is not recognized (use of unresolved identifier)
If I remove the parameter void (*callback_function)()
then the function is recognized again.
What can I do to pass a Swift function address to C and have it called back? Is it possible? Thanks