Right-Left Rule

From C Programming Guide, Jack Purdum, Que Corp. 1983
(Via Advanced C Tips and Techniques, Anderson & Anderson, Hayden Brooks)

  1. Start with the identifier
  2. Look to the right for an attribute
  3. If none is found, look to the left.
  4. If found, substitute English keywork.
  5. Continue right-left substitutions as you work your way out.
  6. Stop when you reach the data type in the declaration.


This rule applies to and C/C++ declaration, simple or complex.

Declarations

Symbol - English keyword
() - function that returns
[n] - Array of n
[n][m] - Array of n arrays of m
* - pointer to



Examples

Declaration - Meaning
unsigned long buf[10]; - buf is an array of 10 unsigned longs
unsigned long *p[2]; - p is an array of 2 pointers to unsigned longs
char *ps[3][4]; - ps is an array of 3 arrays of 4 pointers to characters
int (*pf[5]) (); - pf is an array of 5 pointers to functions that return integers
double *pf; - pf is a pointer to a double
(*pf)() - pf is a pointer to a function
double *(*pf)() - pf is a pointer to a function that returns a pointer to a double
double (*(*pf)())[3][4] - pf is a pointer to a function that returns a pointer to an 3 by 4 array of doubles