[Question] About mixin, template and alias

monarch_dodra monarchdodra at gmail.com
Sun Sep 22 23:30:59 PDT 2013


On Sunday, 22 September 2013 at 21:18:13 UTC, Michael wrote:
>> This:
>> //----
>>    auto eventObserver =  new Event!DelegateType();
>> //----
>> Does not do what you think it does: It *statically* 
>> initializes "eventObserver" to the *single* "new 
>> Event!DelegateType();". SO basically, all your instances are 
>> sharing the same Event.
>>
>> I'm surprised this compiles at all, what with Fire.init 
>> depending on a run-time call, but apparently, dmd is "smart 
>> enough" to do the allocation at compile time.
>
> Why like "static"?

Because that is the definition of inline initialization. 
Basically, every type (struct/class) has a ".init" state, which 
is a compile-time known static initial value.

So when you write "auto a = new A;" It means a resolves to the 
*value* which is the result of "new A". This is not to be 
confused with the *expression*.

In any case, I think the code is wrong to begin with, since you 
are basically using a non shared to access a non-TLS global.

I'm filing a bug report right now.


More information about the Digitalmars-d-learn mailing list