[Dlang-study] [lifetime] destructor, difference between C++ and D and rationale

deadal nix deadalnix at gmail.com
Wed Oct 28 17:29:57 PDT 2015


I think it is very relevent here as destructor is a very common tool to
free resources, as well as one of the most complex to deal with, mostly
because of move semantic. I already had in mind to launch that subject
before this whole thing started.

Why were things changed that way ?
On Oct 28, 2015 15:33, "Andrei Alexandrescu" <andrei at erdani.com> wrote:

> On 10/28/2015 04:39 PM, deadal nix wrote:
>
>> Andrei, to quote you :
>> "[...]at least in v1.0 we're considering having the callER do the
>> increment and the callEE do the decrement. This is how D currently
>> handles copy construction and destruction, and it turns out it has a
>> number of advantages over C++ (where the caller does all the work)."
>>
>> Can you explain how C++ and D destructor management differs, and what
>> are the rationale behind these differences ?
>>
>
> Not much of the place here, but in brief in C++ consider the call:
>
> class C { ... };
> void fun(C);
> int main() { C obj; fun(obj); }
>
> In the call to fun, the callER calls the copy ctor of C, invokes fun, then
> calls the dtor of C.
>
> In D, the callER calls the copy ctor, but it's the callEE that calls the
> dtor.
>
>
> Andrei
> _______________________________________________
> Dlang-study mailing list
> Dlang-study at puremagic.com
> http://lists.puremagic.com/cgi-bin/mailman/listinfo/dlang-study
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/dlang-study/attachments/20151028/9ece3c35/attachment-0001.html>


More information about the Dlang-study mailing list