C - Complicated Declarations

From EdWiki

Revision as of 09:30, 23 June 2015 by Jshankar (Talk | contribs) (1 revision imported: EdWiki -- Emsys pages from Shukra)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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.