Performance improvements for D / DMD compiler.
Walter Bright
newshound at digitalmars.com
Fri Jan 19 23:23:51 PST 2007
Andrei Alexandrescu (See Website For Email) wrote:
> No, and for a good reason:
>
> foo(LargeStruct s1, LargeStruct s2)
> {
> ...
> }
> ...
> LargeStruct s;
> foo(s, s);
>
> Nobody would enjoy hidden aliasing of s1 and s2.
There's another aliasing case:
LargeStruct s;
foo(s);
... here some other thread modifies s ...
And foo() suddenly has its argument values change unexpectedly.
Value and reference type usages mostly overlap, but they are
fundamentally different, and having the compiler switch between the two
in some implementation-defined manner (as suggested by others more than
once) is not going to work.
If one is needing reference behavior from a struct, seriously consider
making it a class instead. Or even just take the address of it and pass
the pointer.
More information about the Digitalmars-d
mailing list