'static' keyword for positional array initialization

Ali Cehreli acehreli at yahoo.com
Wed Aug 12 01:46:18 PDT 2009


Lars T. Kyllingstad Wrote:

> I've tried with DMD 2.031, and I can't reproduce this. This works fine 
> for me:
> 
>    int[2] static_0 = [ 1, 1 ]:
>    int[2] static_1 = [ 1:1 ];
> 
> Where did you put the declarations? I've tried putting them at both 
> module level and in a class, and both times it compiled without problems.

Thank you very much for both of your answers. :)

I hadn't realized that the location of the definitions would make a difference. As you say, both of the lines work for me in the global scope (probably in a class too), but not in main:

void main()
{
    int[2] static_0 = [ 1, 1 ];
    int[2] static_1 = [ 1:1 ];
}

dmd: init.c:431: virtual Expression* ArrayInitializer::toExpression(): Assertion `j < edim' failed.

The 'static' keyword on the 1:1 line fixes the problem...

I am wondering what the correct syntax is... I am writing a D tutorial, so I think I ought to know. :D If this is a bug, I can leave a temporary note mentioning the bug... :)

Ali



More information about the Digitalmars-d-learn mailing list