← Back to context

Comment by jcranmer

6 hours ago

The best summary--and easiest to remember, IMHO--is that variables are declared as they are used.

Want to write an array of function pointers that return a pointer to an array of pointers to int? Well, that's:

  array ... -> x[N]
  ... of function pointers ... -> T (*x[N])()
  ... that return a pointer ... -> T *(*x[N])()
  ... to an array ... -> T (*(*x[N])())[M]
  ... of pointers ... -> T *(*(*x[N])())[M]
  ... to int ... -> int *(*(*x[N])())[M]

It doesn't make it all that easy to read, but you can at least write the complex types pretty reliably.

(The real answer is of course to just typedef every function pointer type or pointer-to-array and not worry about it anymore.)