how to initialize immutable 2 dim array
Michal Minich
michal.minich at gmail.com
Sun Oct 31 12:13:33 PDT 2010
On Sun, 31 Oct 2010 14:53:42 -0400, bearophile wrote:
> import std.stdio: writeln;
>
> int[256][256] arr;
>
> static this () {
> auto pArr = &arr;
> foreach (y; 0 .. (*pArr)[0].length)
> foreach (x; 0 .. (*pArr).length)
> (*pArr)[x][y] = x * y;
> }
>
> void main() {
> writeln(arr);
> }
>
> (I have just fixed your code locally, I don't know what you are doing
> and why you are using a pointer to a fixed sized array, it's an unusual
> idiom in D.)
>
> Bye,
> bearophile
(*pArr)[x][y] = .. fixes it!
Thank you!
I need to use this workaround because global array I want to initialize
in module constructor is immutable.
More information about the Digitalmars-d-learn
mailing list