Article View: comp.std.c++
Article #2601Re: Global Init/Shutdown: A solution (hopefully)
From: J. Kanze
Date: Fri, 17 Nov 1995 00:41
Date: Fri, 17 Nov 1995 00:41
55 lines
3273 bytes
3273 bytes
Herb Sutter (herbs@interlog.com) wrote:
|> In article <9511141105.AA01230@lts.sel.alcatel.de>,
|> James Kanze US/ESC 60/3/141 #40763 <kanze@lts.sel.alcatel.de> wrote:
|> >|> >Another interesting case:
|> >|> >
|> >|> > A a1 ;
|> >|> > A a2 ;
|> >|> > A a3 ;
|> >|> > // ...
|> >|> >
|> >|> >The constructor of a2 throws an exception
|> >|>
|> >|> Trying the above under BC++ 4.52, A::A() is called twice and then
|> >|> A::~A() is called once, which is correct.
|> >
|> >The only compiler I have access to that supports exceptions is Sun CC
|> >4.0.1; this is the compiler I used for my initial tests. I modified
|> >the test to call exit, instead of throwing an exception, and got the
|> >following results:
|> >
|> > ctors dtors
|> > Sun CC 4.0.1 (w/ exceptions) 2 3
|> > Sun CC 2.1 2 0
|> > Cfront 3.0.1 (direct port, not from Sun) 2 3
|> > g++ 2.6.3 2 0
|> > g++ 2.7.0 2 0
|> Hold on... you changed the question! :-) If I modify my BC++ 4.52 program
I had to. The Cfront based compilers and g++ don't support exceptions!
|> to call exit() (instead of throwing) in a2's ctor, I get the incorrect
|> result of three A::~A() calls. If I change it to call abort() in a2's
|> ctor, I get zero A::~A()s.
|> Does the WP specify what/how dtors should be called in the case of an
|> exit() or abort()?
Yes and no. In the case of abort, it is explicit: no destructors are
called. In the case of exit... I can find no statement forbidding
calling exit from a constructor, or saying that it is undefined
behavior. So one must suppose that it is permitted. But calling a
destructor on an uninitialized object will forceably result in undefined
behavior. Whence I conclude that an implementation may not generate
code which does so *unless* my program already contains undefined
behavior.
--
James Kanze (+33) 88 14 49 00 email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
Conseils, itudes et rialisations en logiciel orienti objet --
-- A la recherche d'une activiti dans une region francophone
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<48f240$pjb@gabi.gabi-soft.fr>Path:
arc1-ca.pugleaf.net!in1.uu.net!bounce-backReferences:
<199511110318.UAA24570@ncar.ucar.EDU> <4873sc$hum@gabi.gabi-soft.fr> <488tdp$1tu@steel.interlog.com> <9511141105.AA01230@lts.sel.alcatel.de> <48d93i$4ts@steel.interlog.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back Date: 17 Nov 95 00:41:16 GMT Approved: fjh@cs.mu.oz.au From: kanze@gabi-soft.fr (J. Kanze) Newsgroups: comp.std.c++ Subject: Re: Global Init/Shutdown: A solution (hopefully) X-Original-Date: 16 Nov 1995 11:00:32 +0100 Organization: GABI Software, Sarl. Message-ID: <48f240$pjb@gabi.gabi-soft.fr> References: <199511110318.UAA24570@ncar.ucar.EDU> <4873sc$hum@gabi.gabi-soft.fr> <488tdp$1tu@steel.interlog.com> <9511141105.AA01230@lts.sel.alcatel.de> <48d93i$4ts@steel.interlog.com> X-Newsreader: TIN [version 1.2 PL2] X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUBMKvapeEDnX0m9pzZAQFRuQGAmcM253QdMFAbzz/nNuDsfLqkO+WT8MkK mJwWCN1PPmgjRHJsqXGmXLvcc2d8mfGp =FxTA