Confusing behaviour of array member assignment when calling local function
Sahan Fernando
sahan.h.fernando.alt at gmail.com
Sun Jan 5 14:10:25 UTC 2025
On Sunday, 5 January 2025 at 02:33:51 UTC, Steven Schveighoffer
wrote:
> So what is happening here is the left side of the assignment is
> being evaluated first. Then the right side. The right side
> alters `v` by appending (it must reallocate to accomodate the
> new values), and therefore you assign to the *old* `v`.
>
> ...
>
> You can read more about how arrays work here:
> https://dlang.org/articles/d-array-article.html
>
> -Steve
Ok, that article helped clear up some of the misunderstanding, I
guess it makes sense why it works the way it does. It still feels
a bit counterintuitive, but I guess I should just treat it as
another thing to avoid doing by accident (similar to modifying a
collection while iterating over it). Thanks for the reply!
More information about the Digitalmars-d
mailing list