Article View: comp.std.c++
Article #417Ordering constraints on static constructors/destructors
From: Tom Kelly
Date: Wed, 22 Aug 1990 20:08
Date: Wed, 22 Aug 1990 20:08
46 lines
1791 bytes
1791 bytes
In section 12.6.1 of the ARM, it says:
Constuctors for non-local static objects are called in the
order they occur in a file; destructors are called in
reverse order. See also 3.4, 6.7, 9.4.
In section 3.4, it says:
The initialization of non-local static objects (3.5) in
a file is done before the first use of any function
or object defined in that file. ... No further order
is imposed on the initialization of objects from different
files.
These rules impose a partial order on the intialization of non-local
static objects. Typically, the implementation chooses a total
ordering that is compatible with the partial order.
Later in section 3.5 it says:
Destructors (12.4) for initialized static objects are called
when returning from main() and when calling exit().
Destruction is done in reverse order of initialization.
Does the last sentence mean that the destructor order is constrained
to be the reverse of the total order actually executed for this run
of the program, or just that it must be compatible with the reversed
partial order?
For example, if I have in file1:
foo A;
foo B;
and in file2
foo C;
then construct A, construct B, construct C is a valid ordering for
initialization. Is destruct B, destruct A, destruct C a valid
ordering for termination?
Tom Kelly (416) 922-1937
SCO Canada, Inc. (formerly HCR) 130 Bloor St. W., Toronto, Ontario, Canada
{utzoo, utcsri, uunet}!scocan!tom
Technical Details
Message-ID:
<1990Aug22.160805.8519@sco.COM>Path:
arc1-ca.pugleaf.net!utzoo!telly!attcan!ncrcan!scocan!tomShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!telly!attcan!ncrcan!scocan!tom From: tom@sco.COM (Tom Kelly) Newsgroups: comp.std.c++ Subject: Ordering constraints on static constructors/destructors Message-ID: <1990Aug22.160805.8519@sco.COM> Date: 22 Aug 90 20:08:05 GMT Organization: SCO Canada, Inc. (formerly HCR Corporation) Lines: 46