std.string.toString(char*) little nuisance

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Tue Mar 13 03:29:37 PDT 2007


Tom wrote:
> Frits van Bommel escribió:
>> Tom wrote:
>>> shouldn't be documented on the 'std.string.toString(char*)', that the 
>>> d-string returned shares the same buffer as the input c-string?
[snip]
>>
>> I think it's pretty obvious if you read the first paragraph of 
>> http://www.digitalmars.com/d/phobos/std_string.html, and consider that 
>> a char* c-string is also a 'string' as described in that bit of text. 
>> It's not modified, so a slice of the original is returned (as a D 
>> char[]).
> 
> It wasn't so obvious for me. I knew the COW thing for char[] but didn't 
> guess that a char* was considered a string in this matters.
[snip]
> Not reading wasn't the issue. It was disregarding the 
> fact that in D, a char* is also considered a string.

Well, char* isn't typically considered a string in D, but in this 
case[1] it's treated as one[2].
Also, you clearly referred to it as a (c-)string in your original post ;).


[1]: And AFAIK only in this case, outside of *.c.* modules. Well, 
perhaps you could also count the return value of toStringz...

[2]: The description of toString(char*):  "Convert C-style 0 terminated 
_string_ s to char[] string." (emphasis added)


More information about the Digitalmars-d-bugs mailing list