Proposal: clean up semantics of array literals vs string literals

Andrej Mitrovic andrej.mitrovich at gmail.com
Tue Oct 2 05:02:48 PDT 2012


On 10/2/12, Don Clugston <dac at nospam.com> wrote:
> A proposal to clean up this mess
> --------------------------------
>
> Any compile-time value of type immutable(char)[] or const(char)[],
> behaves a string literals currently do, and will have a \0 appended when
> it is stored in the executable.
>
> ie,
>
> enum hello = ['H', 'e', 'l', 'l', 'o', '\n'];
> printf(hello);
>
> will work.

What about these, will these pass?:

enum string x = "foo";
assert(x.length == 3);

void test(string x) { assert(x.length == 3); }
test(x);

If these don't pass the proposal will break code.


More information about the Digitalmars-d mailing list