Proposal: clean up semantics of array literals vs string literals

Jakob Ovrum jakobovrum at gmail.com
Thu Oct 4 01:11:47 PDT 2012


On Thursday, 4 October 2012 at 07:57:16 UTC, Bernard Helyer wrote:
> On Tuesday, 2 October 2012 at 15:14:10 UTC, Andrei Alexandrescu 
> wrote:
>> First, I think zero-terminated strings shouldn't be needed 
>> frequently enough in D code to make this necessary.
>
> My experience has been much different. Interfacing with C occurs
> in nearly every D program I write, and I usually end up passing
> a string literal. Anecdotes!

Agreed. I'm always happy when I find that the particular C API I 
am working with supports passing strings as a pointer/length pair 
:)

Anyway, toStringz (and the wchar and dchar equivalents in 
std.utf) needs to be fixed regardless - it currently does a 
dangerous optimization if the string is immutable, otherwise it 
unconditionally concatenates. We cannot rely on strings being GC 
allocated based on mutability. Memory is outside the scope of the 
D type system - we cannot make assumptions about memory based on 
types.



More information about the Digitalmars-d mailing list