Hiding the Cumbersome Syntax of Pointers to Functions
Can you tell what the following declaration means?
void (*p[10]) (void (*)());
p is an "array of 10 pointers to a function returning void and taking a pointer to another function that returns void and takes no arguments." The cumbersome syntax is nearly indecipherable, isn't it? You can simplify this declaration considerably by using typedefs. First, declare a typedef for "pointer to a function returning void and taking no arguments" as follows:
typedef void (*pfv)();
Next, declare another typedef for "pointer to a function returning void and taking a pfv":
typedef void (*pf_taking_pfv) (pfv);
Now declaring an array of 10 such pointers is a breeze:
pf_taking_pfv p[10]; /*equivalent to void (*p[10]) (void (*)()); but much more readable*/