Does 'D' language supports 'C' like VLA?
BS & LD via Digitalmars-d
digitalmars-d at puremagic.com
Mon Apr 13 10:37:18 PDT 2015
On Monday, 13 April 2015 at 17:32:31 UTC, Dmitri Makarov wrote:
> 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...
Who wants the compiler creating un-efficient code? I supposed
that I would need to write more complex code in order to fool it
that 'szArr' isn't known at compile-time or even make it really
so.
More information about the Digitalmars-d
mailing list