refInt = ref int: how to achieve this? or is this a bug?
Stanislav Blinov
stanislav.blinov at gmail.com
Wed Jun 17 22:47:20 UTC 2020
On Wednesday, 17 June 2020 at 22:09:35 UTC, mw wrote:
> My thought is that: pointer and reference are all types of its
> own right:
>
> typedef `int*` is ptr in C++
> typedef `int&` is ref in C++
>
> and can you see the beauty of this symmetry? :-)
No, I can't.
typedef int* intPtr;
const intPtr ip = new int;
typedef int& intRef;
const intRef i = 3; // oops, does not compile
> In D, alias can correctly treat int* as pointer type, but treat
> `ref int` as `int`, this break the symmetry
ref int is not a type. What should break is the line
alias intRef = ref int;
should not compile. Looks like it does compile. That's a bug.
> alias `int*` is ptr in D
> alias `ref int` becomes *int* in D
>
> can you see the visual ugliness of this? :-) not even to
> mention the semantic ugliness:
You're conflating reference types and pass by reference. These
are not the same thing in D, and never will be.
More information about the Digitalmars-d
mailing list