开发者

What is the signature of a function that takes in a function pointer and returns a function pointer?

开发者 https://www.devze.com 2023-03-07 21:52 出处:网络
I would like to know what is the signature of a fun开发者_Go百科ction that takes in a function pointer and returns a function pointer?

I would like to know what is the signature of a fun开发者_Go百科ction that takes in a function pointer and returns a function pointer?

Thanks,

Sen


E.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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消