Static arrays, typeof and IFTI?

simendsjo simendsjo at gmail.com
Tue Oct 11 13:46:43 PDT 2011


On 11.10.2011 22:31, Don wrote:
> On 11.10.2011 18:54, bearophile wrote:
>> Andrei Alexandrescu:
>>
>>> I was more enthused about that, but later I realized there are very few
>>> situations in which one reasonably has a fixed-size array that is large
>>> enough to make counting inadequate and is also updated often enough to
>>> make the feature worthwhile. It's one of those features that are nice to
>>> have but are not really missed in real code.
>>
>> I am not going to appreciate a language/compiler that accepts and
>> compiles this program silently. This trap has caused a bug in my code
>> time ago:
>>
>> int[3] a = [1, 2];
>> void main() {}
>
> I've hit that bug many, many times. But...
>
>> The usage of [$] in that case avoids that kind of bug...
>
> How? The code above would still compile. Would be much better to just
> ban assigning an array literal to an static array of different length.
>

// It's important that a has a length of 3, so I specify it
int[3] a = [1, 2]
Error: Not enough values for a. Expected 3, got 2

// I don't care what length a has as long as it has a static length
int[$] a = [1, 2];


More information about the Digitalmars-d mailing list