unsafe toString() behavior

Chris Miller chris at dprogramming.com
Mon Jun 26 16:24:00 PDT 2006


On Mon, 26 Jun 2006 19:18:15 -0400, lenfestey at geemail.com  
<lenfestey_member at pathlink.com> wrote:

> import std.stdio;
> import std.string;
>
> void main() {
> char[] x = toString(0);
>
> // la de da...
> x[0] = 'a';
>
> // guess what i print
> writefln("x=%s", toString(0));
> }
>
> It is because toString(uint) sometimes returns an array slice.
>
> Aaron Lenfestey

In D you have to practice COW (copy-on-write) unless you are certain you  
are the only one using the memory.



More information about the Digitalmars-d-bugs mailing list