0

In C, one can declare pointers to functions like that:

void (*Func1)(int)

I believe that I've understood what this means (in this case, a pointer to a function which returns void and takes an int as parameter) and how to declare and use such pointers.

However, I now have come across declarations like the following:

void (*Func2(int, int))(int)

I am struggling with understanding this syntax. What exactly is declared here? Probably it is a pointer to a function, but I always thought that the closing round parenthesis after the pointer's name is necessary then, so I am completely unsure now.

Could anybody explain, step by step, what the above declaration means?

  • Perhaps it is a pointer to a function that returns a pointer to a function. – sashoalm May 03 '22 at 09:15
  • 2
    [cdecl.org](https://cdecl.org/) ==> *declare Func2 as function (int, int) returning pointer to function (int) returning void* or, in my words, `Func2()` returns a function pointer. – pmg May 03 '22 at 09:16
  • Thanks. Didn't know about cdecl.org - already have bookmarked it. – GreenElephant May 03 '22 at 09:18
  • Perhaps it's best understood with the "declaration mirrors use" rule. The declaration is trying to look like how you could use it. E.g. `(*Func2(1,2))(3)` is a valid call, and the return type of that call is void. – user253751 May 03 '22 at 09:28
  • Excellent explanation - thanks a lot! Got it now ... – GreenElephant May 03 '22 at 09:35

1 Answers1

0

From https://cdecl.org/?q=void+%28*Func2%28int%2C+int%29%29%28int%29

void (*Func2(int, int))(int)

declare Func2 as function (int, int) returning pointer to function (int) returning void

sashoalm
  • 75,001
  • 122
  • 434
  • 781