home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!enterpoop.mit.edu!ira.uka.de!slsvaat!josef!kanze
- From: kanze@us-es.sel.de (James Kanze)
- Subject: Re: When Are Global Objects with a Constructor Initialized?
- In-Reply-To: steve@taumet.com's message of Mon, 25 Jan 1993 17:46:02 GMT
- Message-ID: <KANZE.93Jan28192341@slsvdnt.us-es.sel.de>
- Sender: news@us-es.sel.de
- Organization: SEL
- References: <1993Jan25.024402.10801@alchemy.chem.utoronto.ca>
- <1993Jan25.174602.20429@taumet.com>
- Date: 28 Jan 93 19:23:41
- Lines: 40
-
- In article <1993Jan25.174602.20429@taumet.com> steve@taumet.com (Steve
- Clamage) writes:
-
- |> mbersohn@alchemy.chem.utoronto.ca (M. Bersohn) writes:
-
- |> > Does anyone know when global objects of a class with
- |> >a constructor that does initializations are initialized,
- |> >at compile time or at the beginning of execution?
-
- |> Global objects with constructors are initialized before the first
- |> statement of main() is executed. Within one compilation unit, they
- |> are initialized in definition order, except that objects with a
- |> default initialization to zero are initialized first. The C++
- |> Committee is working on a way to specify that objects initialized with
- |> constant expressions get initialized before other objects. (Current
- |> implementations usually work this way anyhow.)
-
- This is not what it says in the ARM. To quote (section 3.4):
-
- The initialization of nonlocal static objects in a translation
- unit is done before the first use of any function or object
- defined in that translation unit. Such initializations may be
- done before the first statement of main(), or deferred to any
- point in time before the first use of a function or object
- defined in that translation unit.
-
- I seem to recall reading that someone (I think it was HP) was actually
- working on a C++ implementation in which this would be the case;
- nonlocal static objects in a translation unit would only be
- initialized immediately before the first use of a function or object
- defined in that translation unit. Further: if no function or object
- in a translation unit is used during a run of the program, the static
- objects in that translation unit would never be initialized. (This
- frequently occurs in interactive programs, where the user will only
- use a small subset of the commands available in any one session.)
- --
- James Kanze email: kanze@us-es.sel.de
- GABI Software, Sarl., 8 rue du Faisan, F-67000 Strasbourg, France
- Conseils en informatique industrielle --
- -- Beratung in industrieller Datenverarbeitung
-