The daily D riddle

Shachar Shemesh shachar at weka.io
Sun Jan 28 06:44:06 UTC 2018


On 28/01/18 08:33, Mike Franklin wrote:
> On Sunday, 28 January 2018 at 06:25:51 UTC, Shachar Shemesh wrote:
>> What will the following code print? Do not use the compiler:
>>
>> import std.stdio;
>>
>> struct A {
>>     int a = 1;
>>
>>     void initialize() {
>>         a = a.init;
>>     }
>> }
>>
>> void main() {
>>     A a;
>>     a.initialize();
>>
>>     writeln(a.a);
>> }
>>
>> I find this behavior unexpected.
> 
> Works exactly as I predicted.

Good for you.

I think the compiler should warn about such a case.


More information about the Digitalmars-d mailing list