Array void init
eles
eles at eles.com
Fri Apr 26 10:10:47 PDT 2013
On Friday, 26 April 2013 at 15:59:32 UTC, Luís Marques wrote:
> On Friday, 26 April 2013 at 15:45:27 UTC, eles wrote:
>> which reminds me about the proposal to allow declaration of
>> static arrays with
>> double[$] foo = [1.0, 2.0, void, 3.0, 3.5, void, void, void];
>
> Seems nice.
>
>> double[4] foo = [1.0, 2.0];
>> is accepted, which is a bit strange (I think the compiler
>> should give at least a warning if too many elements are
>> reserved for an array).
>
> I just read that as "the other are NaN/.init initialized",
> which seems reasonable. The dollar notation is better than the
> warning here, to say that the array initializer is the
> authoritative source of the array length.
I thought about it. However, it is not very nice. What if
somebody types 1024 instead of 024 for an array length? The error
could pass through the compiler and crash an out of memory after
years of use.
OTOH, I would like to be able to specify a partial initialization
of the first elements of an array, then a default/imposed value
for the remaining elements. So, what about:
double[4] foo = [1.0, 2.0 .. ]; //initializes last 3 elements to
2.0
In this case, obviously, one cannot write
double[$] foo = [1.0, 2.0 .. ]; //the compiler cannot deduce
length of static array
Speaking about the proposal of using "$" in declaring static
arrays whose elements the compiler is able to count (just like in
the double[$] foo = [1.0, 2.0];) I wonder sometimes why so much
reluctance to implement those simple changes (and almost
obvious), while other more dramatic changes are sometimes taken
in a rush. Do not ask for examples, it is a feeling mainly
derived from the discussions about those @property-ies. Speaking
about, what decision was reached to get rid of the compiler
-property flag which is a monster per se? (changes the way the
language is defined).
More information about the Digitalmars-d
mailing list