Syntax syntax
C can be confusing, but you only need one simple rule: read from the inside out . Once you do this, just know that typedef creates a different name (alias) for the type.
The inner part is the declared identifier (or where it will go if absent). Examples:
T a[2]; // array (length 2) of T T* a[2]; // array (length 2) of pointer to T ([] before *) T (*p)[2]; // pointer to array (length 2) of T (parens group) T f(); // function returning T T f(int, char*); // function of (int, pointer to char) returning T T (*p)(int); // pointer to function of (int) returning T T (*f(char, T(*)[2]))(int); // f is a function of (char, // pointer to array (length 2) of T) // returning a pointer to a function of (int) // returning T typedef T (*F(char, T(*)[2]))(int); // F is the type: // function of (char, // pointer to array (length 2) of T) // returning a pointer to a function of (int) // returning T // (yes, F is a function type, not a pointer-to-function) F* p1 = 0; // pointer to F T (*(*p2)(char, T(*)[2]))(int) = 0; // identical to p1 from the previous line
Roger Pate
source share