Reference value of structs not optimized or inlined?
downs
default_357-line at yahoo.de
Fri Aug 28 08:40:10 PDT 2009
Walter Bright wrote:
> Jeremie Pelletier wrote:
>> Isn't it possible to make 'const ref S' or 'in S' generate the same
>> machine code as 'in S*'? To me it would seem the semantics of the two
>> are the same, with 'const S*' being useful syntax for C compatibility
>> while 'in S' and 'const ref S' are both D syntax.
>
> The thing about const is it only specifies a read only view of an
> object, it does *not* specify that the referenced object will not
> change. That is why pass by value cannot be "optimized" to be pass by
> reference.
>
To elaborate on this, consider this case:
import std.stdio;
struct X { int v; }
void test(X x, void delegate() dg) { writefln(x.v); dg(); writefln(x.v); }
void main() {
X ecks;
test(ecks, { ecks.v = 17; });
}
More information about the Digitalmars-d
mailing list