0

I came across a strange function pointer,

void * (*f1(void(*f2)(void)))(int ) ; 

What does the f1 represent here ?

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
Balu
  • 2,247
  • 1
  • 18
  • 23

1 Answers1

4
T (*f(U))(V)

declares f as a function which takes a U and returns a pointer to a function from V to T (i.e. a T (*)(V)).

So f1 is a function that takes a void (*)(void) and returns a void* (*)(int).

Naming the types makes it more readable:

typedef void (*parameter)();
typedef void* (*result)(int);
result f1(parameter f2);

(The name "f2" serves no purpose except for helping the human reading the code interpret it.)

molbdnilo
  • 64,751
  • 3
  • 43
  • 82
  • @Prakash You can think of it that way, but it's not valid syntax. Naming the types using typedefs helps. – molbdnilo Sep 24 '15 at 05:49