Array literals

Steven Schveighoffer schveiguy at yahoo.com
Wed Oct 15 17:53:58 PDT 2008


"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.

And probably no way this gets into D1...

-Steve 





More information about the Digitalmars-d mailing list