Poll: Primary D version
Rainer Deyke
rainerd at eldwood.com
Sun May 23 11:27:03 PDT 2010
On 5/23/2010 07:33, Andrei Alexandrescu wrote:
> On 05/23/2010 12:30 AM, Rainer Deyke wrote:
>> There is no way to define this function with the correct semantics in D.
>> 'toStringz' must append a null character to the string, therefore it
>> cannot return a pointer to the original string data in the general case.
>> If you pass the resulting string to a function that mutates it, then
>> the changes will not be reflected in the original string.
>>
>> If you pass the resulting string to a function that does /not/ mutate
>> it, then that function should be defined to take a 'const char *'.
>
> There is a way, you could simply allocate a copy plus the \0 on the GC
> heap. In fact that's what happens right now.
No, the problem is getting any changes to the copy back to the original.
It can be done, but not with a simple conversion function.
--
Rainer Deyke - rainerd at eldwood.com
More information about the Digitalmars-d
mailing list