refInt = ref int: how to achieve this? or is this a bug?
Steven Schveighoffer
schveiguy at gmail.com
Wed Jun 17 20:47:59 UTC 2020
On 6/17/20 4:38 PM, mw wrote:
> ----------------
> import std.stdio;
>
> alias refInt = ref int;
>
> void f(refInt i) {
> i = 456;
> }
>
> void main() {
> int i = 123;
> writeln(i);
> f(i);
> writeln(i);
> }
> ----------------
>
> $ $DMD/windows/bin64/rdmd.exe reft.d
> 123
> 123
>
> $ $LDC/bin/rdmd reft.d
> 123
> 123
>
> How to achieve this typdef/alias that what I want?
It's not possible in this way. ref is a storage class and not part of
the type.
Essentially, your alias statement becomes:
alias refInt = int;
Which in itself is somewhat of a "feature", as storage classes that do
not apply are ignored. Some may consider it a bug, but I haven't seen
anyone attempt something like what you have, it sure seems like the
compiler should complain.
-Steve
More information about the Digitalmars-d
mailing list