On Friday, 4 August 2017 at 17:44:23 UTC, Timon Gehr wrote:
On 04.08.2017 19:36, Moritz Maxeiner wrote:
Next I run `bar`. I get the same output of "4 4 4 4 4". While
this hack works in C#, I suppose it's reasonable to assume
the D compiler would just reuse stack space for `j`, and that
the C# compiler has some special logic built in to handle
this.
Yes, `j` exists once in foo's stack frame, so the same thing
as in the above happens, because `j`'s value after the loop's
termination is also 4.
Make `j` 'immutable' to appreciate why this behavior is unsound
(this is a form of memory corruption).
I was (explicitly) arguing that it's in keeping with the current
spec.
That the spec is unsound and should be updated is another matter
(on which I agree with you).