First we write a function that takes an int and returns a float.
float First( int f ) { return ( float )f ; }
Then we write a function that takes nothing and returns a pointer to a function that takes an int and returns a float.
This pointer is of the same type as First .
float ( *Second( void ) )( int ) { float (*f)( int ) = First ; return f ; }
Finally, we write a function that takes a char and returns a pointer to a function that takes nothing and returns a pointer to a function that takes an int and returns a float. This pointer is of the same type as Second .
float ( *( *Third( char c ) )( void ) )( int ) { ( void )c ; float ( *(*s)( void ) )( int ) = Second ; return s ; }
If you put the prototypes on top of each other, the strange syntax starts to make sense:
float First ( int ) ; float ( *Second ( void ) )( int ) ; float ( *( *Third( char ) )( void ) )( int ) ;
The only difference from returning a non-functional pointer is that the parameters of the function pointers go at the end of the declaration, and the brackets are:
type* Name( void ) ; function_type (*Name( void ) )( int ) ;
source share