Proposal: clean up semantics of array literals vs string literals

Don Clugston dac at nospam.com
Tue Oct 2 06:08:09 PDT 2012


On 02/10/12 14:02, Andrej Mitrovic wrote:
> 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.

Yes, they pass. The \0 is not included in the string length. It's 
effectively in the data segment, not in the string.




More information about the Digitalmars-d mailing list