Initializing constant AA and shared problems..

simendsjo simendsjo at gmail.com
Sun Mar 18 06:50:00 PDT 2012


I'm trying to initialize an AA, but initializing at definition fails, as  
do in a shared module ctor.

// how is this now constant?
//shared string[int] aa = [1: "a"]; // Error: non-constant expression  
[1:"a"]

// ok
string[int] aa2;
static this()
{
     aa2 = [1: "a"];
}

// The same with shared fails
// segfault
/+
shared string[int] aa3;
shared static this()
{
     aa3 = [1: "a"];
}
+/

// Using __gshared works though
__gshared string[int] aa4;
shared static this()
{
     aa4 = [1: "a"];
}

void main() {
     assert(aa4[1] == "a");
}


More information about the Digitalmars-d-learn mailing list