News for hackers. Stuff that matters.
Re:How to interpret complex C/C++ declarations (2004) by Sharlin on Thursday August 01, 2013 @04:04AM (#6139164)
The main things to remember is that declaration mirrors use, and you don't actually directly declare the type of the variable, you declare the type of the expression that the declaration mirrors.

  // x has type int
  int x;

  // the expression *x has type int
  // -> x is something that, when dereferenced, yields an int 
  // -> x is a pointer to int
  int *x;

  // x[n] has type int for some integer n 
  // -> x is something, when applied the array subscript operator to, yields an int
  // -> x is an array of ints
  int x[5];

  // x() has type int 
  // -> x is something that, when called, returns int
  // -> x is a function returning int
  int x();

  // *x() has type int 
  // -> by operator precedence, calling x, then applying *, yields an int
  // -> x is a function returning a pointer to int
  int *x();

  // (*x)() has type int
  // -> dereferencing x, then calling the result, yields an int
  // -> x is a pointer to a function returning int.
  int (*x)();
Re:How to interpret complex C/C++ declarations (2004) by ygra on Thursday August 01, 2013 @05:14AM (#6139323)
I've never noticed this before. Honestly, this makes things a lot clearer. And while it's still not terribly easy to figure out things like char ((x())[5])() it makes a lot more sense.