0

I came across a strange function pointer,

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

What does the f1 represent here ?

Yu Hao
  • 115,525
  • 42
  • 225
  • 281
Balu
  • 2,557
  • 1
  • 16
  • 22

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
  • 60,978
  • 3
  • 37
  • 76
  • @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