Does 'D' language supports 'C' like VLA?

Dylan Knutson via Digitalmars-d digitalmars-d at puremagic.com
Mon Apr 13 10:24:04 PDT 2015


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


More information about the Digitalmars-d mailing list