🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #763

Re: Order of destructor calls for auto objects

#763
From: Martin O'Nions
Date: Wed, 19 Dec 1990 10:19
44 lines
2558 bytes
jgro@lia (Jeremy Grodberg) writes:

>I cannot find anywhere in the ARM where the order of destruction of
>automatic objects is defined.  Am I missing something?  If not, I propose
>that the ANSI standard add the following to section 6.6 of the ARM:

>  Objects are guaranteed to be destroyed in the reverse of their order
>  of creation.

>We are already guaranteed that a will be constructed first, then b, then c,
>according to section 6.7.  I want to also have the guarantee that on
>exit from scope, first c will be destroyed, then b, then a.  This has
>important implications for objects which reference other objects.

>It appears that CFront 2.0 (from AT&T) already does this, but I would
>like it to be formalized.

As a traditionalist (i.e. a C programmer who views C++ as a interesting
sideline rather then the future of the world) I can't honestly see that
the destruction of the object is the correct phrase for your ammendment.

Would it not be more accurate to refer to "the object destructor call",
which is a tidy-up operation targetted at (for example) freeing of
heap allocated memory, rather then the destruction of the object itself,
which is likely to ocurr on an out-of-scope by the stack pointer being
shifted to simultaneously "destroy" ALL the objects.

Semantics I will agree, but we are talking about an ammendment to the
defined standard...

P.S. is there really a case where there it is essential that one knows
the order of destruction, or is it just a case of planning inter-object
references in an appropriate way - this is NOT a flame, just a query.

Martin

--
DISCLAIMER: All My Own Work (Unless stated otherwise)
--------------------------------------------------------------------------
Martin O'Nions            Logitek Group Support      martino@logitek.co.uk
--------------------------------------------------------------------------
There's been an accident they said/Your servant's cut in half - he's dead!
Indeed said Mr Jones, then please/Send me the half that's got my keys.
         (Harry Graham - Ruthless Rhymes for Heartless Homes)
Technical Details
Message-ID: <martino.661601979@krypton>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!mcsun!ukc!mucs!logitek!martino
References: <1990Dec14.221247.9487@lia>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!mcsun!ukc!mucs!logitek!martino
From: martino@logitek.co.uk (Martin O'Nions)
Newsgroups: comp.std.c++
Subject: Re: Order of destructor calls for auto objects
Message-ID: <martino.661601979@krypton>
Date: 19 Dec 90 10:19:39 GMT
References: <1990Dec14.221247.9487@lia>
Organization: Logitek Plc.
Lines: 45