Creating fixed array on stack
Johan Engelen
j at j.nl
Fri Jan 11 16:31:30 UTC 2019
On Friday, 11 January 2019 at 15:23:08 UTC, Dgame wrote:
> On Friday, 11 January 2019 at 14:46:36 UTC, Andrey wrote:
>> Hi,
>> In C++ you can create a fixed array on stack:
>>> int count = getCount();
>>> int myarray[count];
Small correction: this is valid in C, but not in C++.
>> In D the "count" is part of type and must be known at CT but
>> in example it is RT.
>> How to do such thing in D? Without using of heap.
>
> You could try alloca:
Indeed, but make sure you read up on the caveats of using alloca.
I believe all use cases of VLA/alloca have better alternative
implementation options.
-Johan
More information about the Digitalmars-d-learn
mailing list