[Issue 8384] Poor wchar/dchar* to string conversion support

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jul 13 13:59:10 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=8384



--- Comment #4 from Jonathan M Davis <jmdavisProg at gmx.com> 2012-07-13 13:59:09 PDT ---
format and writeln are supposed to behave the same, because they both operate
on format strings (they _don't_ currently behave 100% the same, but format's
current implementation will be replaced with the new xformat's implementation
in a few months - after the "scheduled for deprecation" time period). to!string
is an entirely different beast.

std.conv.to is asking for an explicit conversion to string, whereas format and
writeln are converting according to the format specifiers, and %s indicates the
default string representation of the type. char*, wchar*, and dchar* are
pointers - _not_ strings - and should not be treated as strings. Pointers print
their address with %s. Making char*, wchar*, and dchar* print themselves as
strings would be inconsistent with other pointer types, and operating on char*,
wchar*, and dchar* should be discouraged, not encouraged.

to!string is treated differently, because you're asking for an explicit
conversion, and we _do_ need to be able to convert null-terminated strings to D
strings.

So, while I can see your point, I really don't think that having format or
writeln treat char*, wchar*, or dchar* as null-terminated strings is a good
idea. We should provide a means of converting them to D strings but not do
anything to encourage using them as-is without converting them.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list