Ali Çehreli:

That is a VLA.

That are currently not present in D. The most common and safe alternatives in D are allocating the memory on the heap with 'new', or over-allocating on the stack a fixed size and then slicing.


If the OP really wants to allocate on the stack, there is the alloca() function (untested, I don't remember the correct name for the memory error):


auto ptr = cast(int*)alloca(num * 2 * int.sizeof);
if (ptr == null)
    throw new outOfMemoryError("...");
auto array = ptr[0 .. num * 2];


Bye,
bearophile

Reply via email to