Weird codegen bug
RazvanN
razvan.nitu1305 at gmail.com
Thu Jun 13 15:42:38 UTC 2019
On Thursday, 13 June 2019 at 13:45:04 UTC, John Colvin wrote:
> On Thursday, 13 June 2019 at 11:28:25 UTC, RazvanN wrote:
>> import std.stdio : writeln;
>>
>> void main()
>> {
>> int a = 7;
>> int b = 9;
>>
>> /* some code later */
>>
>> *(&a + 1) = 2;
>> writeln(b);
>> writeln(b);
>> }
>>
>> This code prints:
>>
>> 9
>> 2
>>
>> with latest version of dmd. Is this a bug or am I missing
>> something? For the record,
>> gdc prints (as expected):
>>
>> 2
>> 2
>
> Why would you think this should work? Locals are not the same
> as struct members, you can't just walk a pointer around.
I think it's odd that b changes its value for no apparent reason.
I understand why it happens, still it is surprising.
More information about the Digitalmars-d
mailing list