How to initialize immutable global static array?

dsimcha dsimcha at yahoo.com
Fri Feb 20 12:51:10 PST 2009


I want to create an immutable global static array, which should be initialized
in a static this() statement at program startup, or at compile time using
CTFE.  This can be done for dynamic arrays, since an immutable array can be
assigned to once in a static constructor, and can be returned from a CTFE
function, but I don't see how to do it for a static array.  Basically I want
something like this:

immutable ubyte[SOMECONSTANT] foo;
static this() {
    // Create array and assign it to foo, and then have foo be  immutable.
}

Or:

immutable ubyte[SOMECONSTANT] foo = someCTFEFunction(someArgument);



More information about the Digitalmars-d mailing list