Can we fix this?

Basile B. b2.temp at gmx.com
Thu Sep 30 02:03:39 UTC 2021


On Thursday, 30 September 2021 at 00:59:26 UTC, deadalnix wrote:
> [...]
> Now, this is expected isn't it? There is one and only one i 
> variable. But let's change things a bit.
>
> ```d
> int i = 1;
> while (i < 4) {
>    int n = i + 2;
>    dgList ~= { writeln(n); }; // still outputs 5 5 5
> }
> ```
>
> Now this is wrong.

Why is this wrong ? Do you expect one alloca per iteration for n ?
It's pretty obvious that variables declared in loops also use the 
same alloca, always. Otherwise what would be required is stack 
save and restore after each iteration.


More information about the Digitalmars-d mailing list