Conditional compilation of array of structs initializer

Tony tonytdominguez at aol.com
Fri Nov 10 06:22:51 UTC 2017


Doing a port of some C code that has an #ifdef in the middle of 
an initialization for an array of structs. I am getting a compile 
error trying to get equivalent behavior with "static if" or 
"version". Is there a way to achieve this other than making two 
separate array initialization sections?

struct a {
    int y;
    int z;
}

immutable string situation = "abc";

int main()
{
    a[] theArray = [
       { 10, 20 },
// version(abc)
static if (situation == "abc")
{
       { 30, 40 },
}
       { 50, 60 }
       ];
    return 0;
}


More information about the Digitalmars-d-learn mailing list