Passing dynamic arrays
Ali Çehreli
acehreli at yahoo.com
Mon Nov 8 11:22:36 PST 2010
Steven Schveighoffer wrote:
> On Mon, 08 Nov 2010 13:35:38 -0500, Daniel Gibson
>> If you pass a dynamic array to a function and chance it's size within
>> the function, you have undefined behaviour - you never know if it will
>> affect the original array (from the calling function) or not.
>
> Not exactly. If you happen to change its size *and* change the original
> data afterwards, then it's somewhat undefined
Let's also note that appending to the array qualifies as "change its
size *and* change the original data afterwards." We cannot be sure
whether appending affects the passed-in array.
> (I'd call it confusing,
> since the behavior is perfectly defined, just hard to describe).
I like the term "discretionary sharing semantics" where any slice can
leave the sharing contract at their discretion regardless of whether
they modified the shared elements so far.
Ali
More information about the Digitalmars-d
mailing list