bug or feature?

Chris Nicholson-Sauls ibisbasenji at gmail.com
Tue Dec 5 06:28:32 PST 2006


bobef wrote:
> import std.stdio;
> import std.string;
> 
> void main()
> {
>     char[] a;
>     char[][] b;
>     a~="1234";
>     b~=a;
>     a.length=0;
>     a~="&&";
>     b~=a;
>     a.length=0;
>     a~="asdf";
>     b~=a;
>     writefln(join(b," "));
> }
> 
> //outputs "asdf as asdf"
> 
> //if we (replace a~="..." with a="...") || (replace a.length=0 with 
> a=null) || (replace b~=a with b~=a.dup) then it outputs "1234 && asdf"
> 
> //i don't know if this is bug or new feature since last time i used d

Its a side-effect of a feature, I believe.  Setting an array's length to 0 no longer 
deallocates the array.  And the ~= in this case is storing the current whole /slice/ of a 
into b.  So its by design, but definitely a potential gotcha!

-- Chris Nicholson-Sauls



More information about the Digitalmars-d-bugs mailing list