declaration/initialization of multidimensional arrays

Tyro[17] nospam at home.com
Sun Nov 18 18:06:58 PST 2012


On 11/18/12 8:14 PM, bearophile wrote:
>> Why is no one complaining about this array allocation syntax?
>
> A syntax I like is:
>
> new double[][3][](N, M)

Why not simply allow new double[N][3][M]; ?
Seems a lot more intuitive/succinct than a separate []() implementation.

> Where:
> - The numbers inside the [] must be always compile-time constants, and
> they always refer to fixed-sized arrays.
> - The numbers inside the () are run-time values and must be used for
> dynamic arrays. (They can be up to the number of empty []. No more. But
> maybe they are allowed to be less).
>
> This means this syntax becomes an error:
>
> int n = 5;
> auto a = new int[n];
>
> You must write:
>
> int n = 5;
> auto a = new int[](n);
>
> This becomes allowed and allocates a fixed-sized array on the heap?
>
> auto a = new int[5];
>
> Bye,
> bearophile




More information about the Digitalmars-d-learn mailing list