std.string.toString(char*) little nuisance

Tom tom at nospam.com
Mon Mar 12 17:55:04 PDT 2007


Frits van Bommel escribió:
> Tom wrote:
>> A question,
>>
>> shouldn't be documented on the 'std.string.toString(char*)', that the 
>> d-string returned shares the same buffer as the input c-string?
>>
>> I've spent some (too much) time debugging to find out why the heck all 
>> my strings were messing up... now I know.
>>
>> Mentioning this on the docs could have been of so much help, it's not 
>> that obvious!
> 
> 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.

> Remember: don't just read the function description, the module 
> description may contain information that applies to all (or a lot of) 
> the functions in a module.

Uhmm, I know :). Not reading wasn't the issue. It was disregarding the 
fact that in D, a char* is also considered a string.

Regards,
--
Tom;


More information about the Digitalmars-d-bugs mailing list