Array literals

Denis Koroskin 2korden at gmail.com
Thu Oct 16 06:45:35 PDT 2008


On Thu, 16 Oct 2008 17:40:23 +0400, Andrei Alexandrescu  
<SeeWebsiteForEmail at erdani.org> wrote:

> Steven Schveighoffer wrote:
>> "bearophile" wrote
>>> By default arrays/strings in D1 are static:
>>>
>>> import std.stdio: writefln;
>>> void main() {
>>>    auto a = ["Hello", "what"];
>>>    writefln(a[2].length); // 5
>>> }
>>>
>>> To remove a significant amount of bugs from my code, like that one  
>>> (the second string is a static array of length 5) I suggest to  
>>> "invert" the meaning of array literals: by default they define dynamic  
>>> arrays/strings allocated on the heap (immutable too, if necessary). So  
>>> a different and explicit syntax can be used/invented to denote static  
>>> arrays.
>>  I think this can be solved even simpler.  Make string literal type be  
>> invariant(char)[] instead of static array.  It does not need to be on  
>> the heap.  That would solve lots of IFTI problems too.
>
> Yah Walter does plan to make "string literals" dynamically-sized by  
> default, but fixed-sized on demand (if you specify the appropriate  
> receiver type, which in turn asks the T[auto] question). In related  
> news, he wants to legitimize statically-typed arrays by making them true  
> value types.
>
> Andrei

Good news!



More information about the Digitalmars-d mailing list