On Monday, 13 April 2015 at 17:24:05 UTC, Dylan Knutson wrote:
On Monday, 13 April 2015 at 17:20:04 UTC, Dmitri Makarov wrote:
This should work the way you want it to:
void main()
{
immutable size_t szArr = 3;
int[szArr] arr;
}
Regards,
Dmitri
No, this isn't what VLA is. Ola Fosheim Grøstad has the right
of it; he'll need to use alloca to dynamically extend the
stack. What OP is referring to is the ability to create a
dynamically sized array on the stack, rather than the heap.
Here's a good description of what VLA is and how it works:
https://en.wikipedia.org/wiki/Variable-length_array
Ah, ok, then why did he complain that the compiler can't
determine that the value of szArr is known at compile-time. A
kind of conundrum, isn't it -- he want's to create arrays on
stack with their sizes known at run-time, but wants the compiler
to figure the size of such an array at compile-time...