So, until now, I was pretty sure my mental pointer-to-function parser was able to parse even the toughest of pointers... how wrong was I! While reading some legacy code I found this:
void (*(*somename)(void (*)()))(void (*)());
Apparently, it means declare somename
as pointer to function (pointer to function returning void
) returning pointer to function (pointer to function returning void
) returning void
(according to http://cdecl.org, at least).
It seems that I oversimplified the way function pointer declarations work. I was pretty sure the syntax is return-type(*variable-name)(argument-types...)
. It works for a lot of cases, but not for complex ones, like above. How could I go about reading such unordinary and complex declarations, without having to think about all the grammar rules and trying to figure out if I should read from left to right or in reverse or in some other weird way?