On Tuesday, 22 December 2020 at 16:56:18 UTC, Ali Çehreli wrote:
On 12/22/20 6:35 AM, ag0aep6g wrote:
> Flip the pointer syntax, too:
>
> *Foo a; /* a pointer to a Foo */
I am not a language expert but I think that would make D's
parsing complicated (like C++'s < token) because * already
means "derefence" in that position. So, the parser would see
*Foo as a potential compilation error but would have to parse
forward, etc.
I'm not seriously suggesting changing D's syntax. The current
syntax is fine with me.
`Foo* a;` is already "complicated", though. `*` can also mean
multiplication in that position:
----
struct F
{
F opBinary(string op : "*")(F a) { return F(); }
void opBinary(string op : "+")(int a) { import std.stdio;
writeln("Hello, world!"); }
}
void main()
{
F Foo;
F a;
Foo* a + 1; /* prints "Hello, world!" */
}
----
That's a convoluted example, of course. But it shows that the
compiler already has to look ahead to decide what the `*` means.
It doesn't just go "That's a type!" when it sees "Foo*".