Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
November 16, 2009 multidimensional dynamic arrays | ||||
---|---|---|---|---|
| ||||
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 Re: multidimensional dynamic arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to Trass3r | 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 Re: multidimensional dynamic arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ellery Newcomer | 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 Re: multidimensional dynamic arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to Trass3r | 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 Re: multidimensional dynamic arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | 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 Re: multidimensional dynamic arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to Trass3r | 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..
|
Copyright © 1999-2021 by the D Language Foundation