Search code examples
cfunction-pointersreturn-typefunction-declaration

What does this convoluted C type declaration mean?


On a programming community I'm in, someone threw this absolute hand grenade into chat:

this is a valid function declaration in c

void* volatile* (*func(unsigned long const long volatile int, signed, long*[*][42]))(__int128* (*) (int* restrict const[static restrict const 17]));

Several of us have had a go at trying to decipher this declaration, but nobody's had any luck just yet.


Solution

  • It will be more easy to understand the function declaration if to represent its declaration

    void* volatile* (*func(unsigned long const long volatile int, signed, long*[*][42]))(__int128* (*) (int* restrict const[static restrict const 17]));
    

    using typedefs.

    The first one can be the following

    typedef _int128* FunctionAsParameter(int* restrict const[static restrict const 17]);
    

    The second one is the following

    typedef void* volatile* FunctionAsReturnType( FunctionAsParameter * );
    

    And at last the original function declaration will look like

    FunctionAsReturnType * func( unsigned long const long volatile int, signed, long*[*][42]);
    

    That is the return type of the function func is a pointer to function that has one parameter that in turn is pointer to function.