DMD 0.177 release

Walter Bright newshound at digitalmars.com
Wed Dec 13 20:39:44 PST 2006


Andrei Alexandrescu (See Website for Email) wrote:
> That makes me wonder - if a = b is used without picking up its result 
> (the usual case), and if opAssign() returns an S, will the compiler 
> optimize away the extra copy at zero cost?

No. The caller and callee don't know about each other.

> What I think happens is that the function will take a pointer to the 
> destination which is zero, so a comparison will be made. But perhaps the 
> optimizer will take care of eliminating that?

You could have a null pointer passed to the return result, but that 
would entail an extra check on the part of the callee.

This is why a lot of C++ code tends to return references instead of values.



More information about the Digitalmars-d-announce mailing list