Static inline field initialization

Kagamin via Digitalmars-d digitalmars-d at puremagic.com
Wed Aug 23 02:12:19 PDT 2017


On Tuesday, 22 August 2017 at 16:28:43 UTC, Moritz Maxeiner wrote:
> class Test
> {
>     ubyte[] buf = new ubyte[1000]; // thread local storage, 
> instances in the same thread refer to the same static array
> }

Dynamic initialization is done by constructor:

class Test
{
     static ubyte[1000] s;
     ubyte[] buf;
     this()
     {
         buf=s;
     }
}

It's also unambiguous as to how it works.


More information about the Digitalmars-d mailing list