home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / cplus / 20035 < prev    next >
Encoding:
Text File  |  1993-01-28  |  2.5 KB  |  54 lines

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