The daily D riddle

Jorge Lima jmalima69 at gmail.com
Wed Jan 31 13:46:07 UTC 2018


On Sunday, 28 January 2018 at 06:44:06 UTC, Shachar Shemesh wrote:
> 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.

I also run the test and it worked as I expected. It seems pretty 
straingtforward logic. I wonder if I didn't get your question 
right. What result were you expecting and why?


More information about the Digitalmars-d mailing list