A seasonal followup to “When is *x also &x?”

Yesterday I wrote:

  • Teach the logic behind C-style declarations. int *p can mean “p is an int*,” and it can equally well mean “*p is an int.” int const *f() can mean “You aren’t allowed to modify the int,” or it can equally well mean “You aren’t allowed to modify *f().” (Of course this only works for pointers, not references; that’s another reason it’s important to reveal pointers early.)

In the Reddit comments, commenter “redditsoaddicting” pointed out that this logic even works for multiple declarations on the same line:

In int *p, q;, the expression *p, q is of type int.

Not only that, but after const int& x(), *y;, we find that decltype(x(), *y) is const int&!

Posted 2020-04-01