C - Complicated Declarations

From EdWiki

Complicated Declarations

  • C is sometimes criticized for the syntax of its declarations, particularly ones that involve pointers to functions.
  • It can be confusing because declarations cannot be read from left to right, and parentheses are over used.

The difference between

int* f(void);	// function returning pointer to int


int (*pf)(void);  // pointer to function returning int

Illustrates the problem. * is a prefix operator and it has lower precedence than (), so parentheses are necessary to force the proper association.