Re:Cppfront, Herb Sutter's proposal for a new C++ syntax
by DerekL on Sunday September 18, 2022 @05:03PM
(#32891480)
Similar problems happen even in C. Suppose you have this line inside a function:
X *y;
Are you declaring a pointer, or are you performing multiplication? It depends on what “X” is.
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax
by tsimionescu on Sunday September 18, 2022 @05:43PM
(#32891771)
True, though in this case as well, just replacing type first to type last would presumably lead to `y *X` which doesn't help so much in resolving ambiguity.
The two examples on Wikipedia are both caused by this, even though it's not explicitly spelled out:
C++ could have also chosen to reserve a keyword for initialization even for in-place values, just like they did with `new`, but they chose to re-use function call syntax instead.I would also say that just moving the type after the variable name doesn't fully solve the issue - it's the : syntax for initialization that does this. Here is a hypothetical C++ where the syntax remained the same as today, but (return) type was moved at the end of a declaration: