Why it doesn't compile in D 2.0?

Simen kjaeraas simen.kjaras at gmail.com
Sun Jan 17 11:56:16 PST 2010


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


More information about the Digitalmars-d-learn mailing list