[Development] The age-old T* foo vs. T *foo

Kevin Kofler kevin.kofler at chello.at
Fri Oct 18 02:37:21 CEST 2019


Ville Voutilainen wrote:
> Since we are about to do a major version upgrade, should be stop being
> a special snowflake in the C++ world and start attaching pointer-stars
> and reference-ampersands to the type instead of to the variable?

No, because it is syntactically not a part of the type, as evidenced by the 
int *x, y; example that others have already pointed out. Semantically, it 
is, but the semantics are only computed after doing the syntactic parsing, 
so the whitespace should preferentially match the syntax.

And I consider the idea of banning comma declarations to work around this 
issue to be nothing more than a workaround for poor notation not matching 
the syntax of the language.

int* x; is just as misleading use of whitespace as:
if (foo)
  bar;
  baz;
(indented this way and without braces).

        Kevin Kofler



More information about the Development mailing list