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

BS & LD via Digitalmars-d digitalmars-d at puremagic.com
Mon Apr 13 09:53:54 PDT 2015


As you know in 'C' you can create a variable-length-array using 
variably modified type and a run-time variable allocating a 
storage for it - the same way for any local (normally using the 
stack).

However in 'D' I don't see such feature. Code like this fails:

void main()
{
     size_t szArr = 3;

     int[szArr] arr;
}

With this error message:

error: variable szArr cannot be read at compile time
      int[szArr] arr;

Life example - http://melpon.org/wandbox/permlink/a6CzBhYk88FohKlf

Note:  I'm also amazed why 'D' compiler can't detect that 'szArr' 
is a constant anyway.


More information about the Digitalmars-d mailing list