Timon Gehr via Digitalmars-d
digitalmars-d at puremagic.com
Fri Aug 4 10:44:23 PDT 2017
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).
More information about the Digitalmars-d