Why does toStringz return an immutable(char)*?

Jonathan M Davis jmdavisProg at gmx.com
Sat Jun 18 21:45:14 PDT 2011


On 2011-06-18 20:59, Adam D. Ruppe wrote:
> I don't know if it does this, but immutable could avoid copying:
> 
> string a = "hello\0";
> 
> auto c_str = toStringz(a);
> 
> assert(c_str is a.ptr); // it already fit the bill so no change needed

Well, the return type doesn't really matter for that as far as const vs 
immutable goes. However, it does look like the current implementation is able 
to avoid copying when given a string explicitly (as opposed to any other type 
of character array), though it ends up copying anything else.

- Jonathan M Davis


More information about the Digitalmars-d mailing list