Proposal: clean up semantics of array literals vs string literals

Tobias Pankrath tobias at pankrath.net
Tue Oct 2 04:18:48 PDT 2012


On Tuesday, 2 October 2012 at 11:10:46 UTC, Don Clugston wrote:
> The problem
> -----------
>
> String literals in D are a little bit magical; they have a 
> trailing \0. This means that is possible to write,
>
> printf("Hello, World!\n");
>
> without including a trailing \0. This is important for 
> compatibility with C. This trailing \0 is mentioned in the spec 
> but only incidentally, and generally in connection with printf.
>
> But the semantics are not well defined.
>
> printf("Hello, W" ~ "orld!\n");
>
If every string literal is \0-terminated, then there should be 
two \0 in the final string. I guess that's not the case and 
that's actually my preferred behaviour, but the spec should make 
it crystal clear in which situations a
string literal gets a terminator and in which not.



More information about the Digitalmars-d mailing list