According to http://www.digitalmars.com/d/1.0/arrays.html#printf "String literals already have a 0 appended to them" But if we create static arrays, they are exactly one after another: import std.stdio; const s1 = "abcd", s2 = "EFG", s3 = "h"; void main() { writefln("%s %s %s\n%s %s %s", s1, *(s1.ptr + s1.length), cast(int) *(s1.ptr + s1.length), s2, *(s2.ptr + s2.length), cast(int) *(s2.ptr + s2.length) ); } Prints: abcd E 69 EFG h 104 If I missed something, I think this "something" should be mentioned in documentation near citation above.
This seems to be windows-specific. The exact code produces this output on linux (as far back as 2.033, the earliest installed compiler I have): abcd 0 EFG 0
(In reply to comment #1) > This seems to be windows-specific. The exact code produces this output on > linux (as far back as 2.033, the earliest installed compiler I have): > > abcd 0 > EFG 0 It is a D1 only issue.
Oops, sorry for the noise.
Actually, I did have a D1 compiler laying around. And I figured out the issue. The issue is D1's type inference treats string literal types as char[N] where N is a uint. Note that D2's type inference treats string literals as immutable(char)[]. So the issue is that you are not declaring a type, and D is assuming you meant it to be a fixed-sized array. So the literal *does* have a zero, but it is copied into your declared fixed-sized arrays in the global segment without the zero. I figured it out by doing: pragma(msg, typeof(s1).stringof); which prints: char[4u]; If you do this: const string s1 = "abcd", s2 = "EFG", s3 = "h"; Then it works as you expect.