Topic: Global Init/Shutdown: A solution (hope
Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1995/11/14 Raw View
In article hum@gabi.gabi-soft.fr, kanze@gabi-soft.fr (J. Kanze) writes:
>JdeBP@jba.co.uk wrote:
>|> : Also, I think that the lifetime of the local static objects and global
>|> : translation units (i.e. sets of global objects defined in them) should
>|> : conform to the single stack-like semantics (actual implementation data
>|> : structure may vary). In other words, the object/unit is 'pushed' when
>|> : its construction starts (or ends). At the implementation-dependent
>|> : moment after main() returns, the implementation shutdown code starts
>|> : 'popping' objects/units from the stack and calling the appropriate
>|> : destructors.
>|> Although not implemented as a stack, you will find that many
>|> implementations already do this, because one favourite means of
>|> implementing global initialisation is to construct at link time a list of
>|> all static duration objectsi from all translation units and bind them into
>|> the program. At runtime this list is traversed from one end to the other
>|> to perform dynamic initialisation, and in the reverse direction to perform
>|> destruction.
>This is, in effect, what most implementations do. By my reading of the
>standard, however, it is *not* legal. ...
At the Tokyo meeting last week, the C++ Committee adopted a resolution
requiring that static objects (local and non-local) be destroyed in
strictly reverse order of construction, where the construction order
is defined as the order in which constructors complete. There are more
details, but the substance is to require the equivalent of what is discussed
above.
---
Steve Clamage, stephen.clamage@eng.sun.com
---
[ 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. ]