January 25, 2014 [dmd-internals] Casting string literal to static array | ||||
---|---|---|---|---|
| ||||
Attachments:
| In test23.d, there is this: void test25() { char[6] cstr = "123456"c; auto str1 = cast(wchar[3])(cstr); writefln("str1: ", (cast(char[])str1).length , " : ", (cast(char[])str1)); assert(cast(char[])str1 == "123456"c); auto str2 = cast(wchar[3])("789abc"c); writefln("str2: ", (cast(char[])str2).length , " : ", (cast(char[])str2)); assert(cast(char[])str2 == "789abc"c); auto str3 = cast(wchar[3])("defghi"); writefln("str3: ", (cast(char[])str3).length , " : ", (cast(char[])str3)); assert(cast(char[])str3 == "d\000e\000f\000"c); } I'm not sure we should allow the cast from "789abc"c to wchar[3]. I think if you want this behavior you should have to do `cast(wchar[3])cast(char[6])"789abc"`. Thoughts? |
Copyright © 1999-2021 by the D Language Foundation