declaration/initialization of multidimensional arrays

bearophile bearophileHUGS at lycos.com
Sun Nov 18 17:14:23 PST 2012


> Why is no one complaining about this array allocation syntax?

A syntax I like is:

new double[][3][](N, M)

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