Topic: Initialization of nonlocal objects with static storage duration


Author: jsberg@hpslap03.cern.ch (J. Scott Berg)
Date: 1996/04/17
Raw View
If one looks at section 3.6.2 of the April WP, one finds the rules
given there for initialization of non-local objects with static
storage duration to be the following:

1) They are initialized before the first use of any function or object
defined in that translation unit.
2) The storage is zero-initialized before any other initialization
takes place.
3) Objects with static storage duration initialized with constant
expressions are initialized before any other initialization takes
place.
4) The order of initialization of nonlocal objects with static storage
duration defined in the same translation unit is the order in which
their definition appears in the translation unit.

I was told that 1) no longer appears in the draft, since it could
become circular, among other things.  What of this, if any, can I
reasonably rely on existing in the final standard?

My reason is that I wish to have classes defined in different
translation units which register themselves with another class via an
initialization of a global object.  The class with which they register
themselves keeps the list in a static member, which must be
initialized before any of the other classes register themselves.  I
had attempted to do this using 1), and when that didn't work, I
reported it as a bug and was told that 1) was no longer part of the
standard.  If I could rely on 2), for instance, I could make a global
pointer to the list and check if it was null, for instance,
initializing the list if it was; 3) would work similarly.

Thank you very much

    -Scott Berg

--
J. Scott Berg                      email: Scott.Berg@cern.ch
Work Phone: (41-22-)767-94-67      Real mail: CERN; SL Division; Bldg 30-2002
Home Phone: (41-22-)783-03-15                 CH-1211 Geneva 23; Switzerland
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]