Length of fixed size arrays

Benjamin Thaut code at benjamin-thaut.de
Sat Nov 17 09:19:50 PST 2012


On Saturday, 17 November 2012 at 17:10:40 UTC, bearophile wrote:
> Benjamin Thaut:
>
>> I'm not quite sure if the .length property of a static array 
>> is always a compile time constant.
>
> Currently it's always a compile-time constant.
>
> But I have asked for some kind of Variable Length arrays 
> allocated on the stack, as in C99, because using alloca() to 
> create a 2D array on the stack is not good, it's noisy, unsafe 
> and bug-prone. In this case their length is contained in some 
> scoped variable or in an argument, at run-time.
>
> They are discussing VLAs again for C++14:
> http://root.cern.ch/drupal/content/c14
>
> Bye,
> bearophile

That would be nice, but a bigger problem I'm currently having, is 
that you can not initialize fixed size arrays like this:

int[4] bla = [1,2,3,4];

Without causing a allocation. The literal will be allocated on 
the heap, then copied onto the stack, and then it will become 
garbage.

Kind Regards
Benjamin Thaut


More information about the Digitalmars-d mailing list