Why it doesn't compile in D 2.0?

aarti_pl aarti at interia.pl
Mon Jan 18 11:53:27 PST 2010


W dniu 2010-01-17 20:56, Simen kjaeraas pisze:
> aarti_pl <aarti at interia.pl> wrote:
>
>> Well, I don't get it...
>>
>> IMHO .dup makes mutable copy of data (so copy of "test") in mutable
>> area of memory. And it should mean that every pointer points to
>> different area of memory...
>>
>> Am I wrong?
>
> You're mostly right. However, this happens at compile time, so the mutable
> data is mutable no longer once its been stored in the executable. IOW,
> "Test".dup is executed once at compile time, and the result stored in
> Test.init. Then, at runtime, Test.init is copied onto each new instance of
> the struct/class. "Test".dup is not executed at runtime.
>
> As Lutger pointed out, this smells of a bug. Sadly, fixing that bug would
> not overcome the problem of having no default constructors for structs.
>
> --
> Simen

Well, in such a case you are right. It's not what I would like to have...

It will be indeed source of bugs.

BR
Marcin Kuszczak
(aarti_pl)


More information about the Digitalmars-d-learn mailing list