Confusing behaviour of array member assignment when calling local function

Nick Treleaven nick at geany.org
Mon Jan 6 12:02:21 UTC 2025


On Saturday, 4 January 2025 at 23:11:58 UTC, Sahan Fernando wrote:
> Hello all,
>
> I've encountered an unexpected behaviour in the D language, 
> where assigning the result of a function that grows an array to 
> a value in that array ends up modifying the old memory used 
> previously by that array. This seems counterintuitive to me in 
> the sense that it feels logical that the lvalue to be assigned 
> to should be evaluated after the function has been evaluated, 
> but this behaviour implies that part of the lvalue was 
> evaluated before the function.

https://dlang.org/spec/expression.html#order-binary says:

> Implementation Defined: The order of evaluation of the operands 
> of AssignExpression.



More information about the Digitalmars-d mailing list