Poll: Primary D version
Rainer Deyke
rainerd at eldwood.com
Sat May 22 22:30:38 PDT 2010
On 5/22/2010 23:16, Mike Parker wrote:
> That's not the problem. The problem is this:
>
> const(char)* toStringz(const(char)[] s);
>
> There's no equivalent for:
>
> char *toStringz(char[] s);
>
> Hence the need to cast away const or use a wrapper for non-const char*
> args.
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 *'.
--
Rainer Deyke - rainerd at eldwood.com
More information about the Digitalmars-d
mailing list