Static initialization of rectangular arrays

rombankzero bogomancer at
Thu Aug 29 15:10:26 UTC 2019

Hey, everybody! I'm having Array Problems™. The documentation on 
arrays says that you can initialize all elements of a rectangular 
array with the following syntax:

> double[6][3] matrix = 0; // Sets all elements to 0.

However this doesn't appear to work for static initialization:

> static double[6][3] matrix = 0; // Error: cannot implicitly 
> convert expression `0` of type `int` to `double[6][3]`

More confusingly, it *does* work for one-dimensional static 

> static double[6] matrix = 0; // Thumbs up from the compiler.

Is this a bug, or am I missing something? It would be really 
convenient to be able to statically initialize rectangular arrays 
in this way. Example: I have a struct that has a member that's a 
rectangular float array, but I have no way of telling the 
compiler that I want it default-initialized to all-zeroes 
(instead of NaNs)!

More information about the Digitalmars-d-learn mailing list