What is the signature of a function that takes in a function pointer and returns a function pointer?
Thanks,
SenE.g.:
void (*f(void (*)(void)))(void)
... which is much more readably using typedefs
:
typedef void (*VoidFunctionPointer)(void);
VoidFunctionPointer f(VoidFunctionPointer);
The easiest way to do this would be with a typedef:
typedef int(*int_fn_ptr)(int);
int_fn_ptr my_func(int_fn_ptr f);
Disclaimer: I can't verify that there are no typos here.
You need to better define the function pointer taken as parameter and return type.
Anyway, here's an example with a simple function.
#include <stdio.h>
#include <stdlib.h> /* abs */
typedef int fx(int);
/* foo takes a function pointer and returns a function pointer */
fx *foo(fx *bar) {
if (bar) return bar;
return NULL;
}
int main(void) {
fx *(*signature)(fx *) = foo; /* signature points to foo */
if (signature(abs)) printf("ok\n");
return 0;
}
精彩评论