[Issue 2093] string concatenation modifies original

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Nov 22 14:31:41 PST 2008


http://d.puremagic.com/issues/show_bug.cgi?id=2093





------- Comment #13 from schveiguy at yahoo.com  2008-11-22 16:31 -------
(In reply to comment #12)
> It seems to me then that this is a design choice  - does the string length
> belong to the string or to the reference? For slices it must be the reference
> but for arrays? hmmm... Curently in D, a dynamic array and a slice are
> indistinguishable and I'm not so sure that should be the case. There are good
> arguments for the current design and also for the separation of slices and
> dynamic arrays.
>
> Common sense seems to say that if I change the length of a string that
> therefore every other reference to the same string should also honour the new
> length, and that this should also have no effect on previously captured slices
> of the string. 

Arrays should not be typed differently than slices IMO, they should be able to
be passed to the same functions.  I think one of the two solutions I proposed
would place the 'allocated length' of an array on the heap with the array data,
thereby having the length stored in a shared location.  Slices should respect
this length, and if they cannot see the length, they should be reallocated as a
full-blown array.


-- 



More information about the Digitalmars-d-bugs mailing list