Thread overview
multidimensional dynamic arrays
Nov 16, 2009
Trass3r
Nov 16, 2009
Ellery Newcomer
Nov 16, 2009
Trass3r
Nov 16, 2009
Trass3r
Nov 16, 2009
Ellery Newcomer
November 16, 2009
What's the short way to create a multidimensional dynamic array? I always forget how to do such stuff due to its strange syntax.

auto array = new ubyte[width*height][numSprites];
doesn't work cause width*height is no "Integer constant expression"
November 16, 2009
Trass3r wrote:
> What's the short way to create a multidimensional dynamic array? I always forget how to do such stuff due to its strange syntax.
> 
> auto array = new ubyte[width*height][numSprites];
> doesn't work cause width*height is no "Integer constant expression"

auto array = new ubyte[][](width*height, numSprites);

params might be backwards..
November 16, 2009
Ellery Newcomer schrieb:
> 
> auto array = new ubyte[][](width*height, numSprites);
> 
> params might be backwards..

Ah yeah, thanks, that was it.
Don't get the reason for that syntax.

Anyway it should really be described in the language docs.
I'd expect it to be at http://www.digitalmars.com/d/2.0/arrays.html
but "Rectangular Arrays" only explains how to declare them.
November 16, 2009
On Mon, 16 Nov 2009 08:42:28 -0500, Trass3r <mrmocool@gmx.de> wrote:

> Ellery Newcomer schrieb:
>>  auto array = new ubyte[][](width*height, numSprites);
>>  params might be backwards..
>
> Ah yeah, thanks, that was it.
> Don't get the reason for that syntax.

Especially now that static arrays are legitimate value types, new ubyte[1][2] looks to the compiler like a dynamic array of 1 ubyte[1]'s.

-Steve
November 16, 2009
Steven Schveighoffer schrieb:
> 
> Especially now that static arrays are legitimate value types, new ubyte[1][2] looks to the compiler like a dynamic array of 1 ubyte[1]'s.
> 

Ah ok.
Maybe it's a good idea to alter the error message when the compiler detects a non-constant expression? Like if you meant to create a dynamic array use the []() syntax..
November 16, 2009
Trass3r wrote:
> Ellery Newcomer schrieb:
>>
>> auto array = new ubyte[][](width*height, numSprites);
>>
>> params might be backwards..
> 
> Ah yeah, thanks, that was it.
> Don't get the reason for that syntax.
> 

I think it has something to do with uniformity inside templates or something.

alias ubyte[][] Foo;

Foo foo = new Foo(1,2);

still not sure about params.. I should look this up..