delegating constructors and "this = ..."

jpf spam at example.com
Mon Feb 8 10:22:02 PST 2010


On 08.02.2010 18:26, BCS wrote:
> 
> 'this' is a mutable *local* reference (IIRC it is in fact a hidden 1st
> argument to the function). All the 'this =' lines does is assign to a
> local value that is discarded immediately. If asserts are turned off,
> the optimizer would even be free to just dump the then clause from that
> code as a dead assignment.
> 
> ('this' being mutable might be considered a bug in the spec)
> 
>>
> -- 
> <IXOYE><
> 
> 
Oops, I didn't know that. That explains why I didn't see assigning to
this mentioned in the docs. I got the assigning idea from gtkd, they use
this as well. One thing is strange though: If you look at the test case,
in the end:
-------------------------------------
Test test1 = new Test(&a);
Test test2 = new Test(&a);
	
assert(test1 is test2); /* ok */
-------------------------------------
This works, test1 and test2 reference the same object, which means "this
= lookupTable[ptr];" does not only change the local reference when "this
(void* ptr)" is invoked directly. If this is a local reference only,
that shouldn't work at all, correct?




More information about the Digitalmars-d mailing list