Why aren't wide string literals zero-terminated just like strings?

Andrej Mitrovic none at none.none
Wed May 18 13:57:37 PDT 2011


Skip the rest of the code until you reach main:
http://codepad.org/zPAgFnPX

We have this notion that string *literals* are zero-terminated, which enables us to send them to C functions expecting zero-terminated char* strings.

But the same doesn't apply to wide string literals, e.g. "somestring"w. If it did, its would save quite a bit of typing when calling WinAPI functions that expect wide strings, instead of having to call "somestring".toUTF16z.

So currently:
immutable(char)[] literal implicitly convertible to const(char)* and char*.
immutable(wchar)[] literal not implicitly convertible to const(wchar)* and wchar*.


More information about the Digitalmars-d-learn mailing list