Thread View: comp.std.c++
2 messages
2 total messages
Started by Tom Kelly
Wed, 22 Aug 1990 20:08
Ordering constraints on static constructors/destructors
Author: 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
Re: Ordering constraints on static constructors/destructors
Author: Andrew Koenig
Date: Thu, 23 Aug 1990 16:40
Date: Thu, 23 Aug 1990 16:40
19 lines
1192 bytes
1192 bytes
In article <1990Aug22.160805.8519@sco.COM>, tom@sco.COM (Tom Kelly) writes: > 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? It means that the objects must be destroyed in precisely the reverse order of their construction. It's not good enough to pick a random one of the inverses of the partial ordering. -- --Andrew Koenig ark@europa.att.com
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads