Static constructors in structs.

TheFlyingFiddle via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Oct 30 14:12:39 PDT 2015


On Friday, 30 October 2015 at 20:58:37 UTC, anonymous wrote:
> On 30.10.2015 21:23, TheFlyingFiddle wrote:
>> Is this intended to work?
>>
>> struct A
>> {
>>     __gshared static this()
>>     {
>>        //Add some reflection info to some global stuff.
>>        addReflectionInfo!(typeof(this));
>>     }
>> }
>>
>> I just noticed this works in 2.069, is this intended?
>
> static constructors are supposed to work, yes.
>
> The description is on the class page: 
> http://dlang.org/class.html#static-constructor
>
> __gshared doesn't do anything there, though. Use `shared static 
> this` instead, if you want the constructor to run only once per 
> process, and not once per thread.

Was under the impression that __gshared did the same thing for 
static constructors. Thanks.


More information about the Digitalmars-d-learn mailing list