Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!zaphod.mps.ohio-state.edu!van-bc!ubc-cs!uw-beaver!milton!sumax!polari!rwing!seaeast!sunbrk!Usenet From: Greg.Comeau@sunbrk.FidoNet.Org (Greg Comeau) Newsgroups: comp.lang.c++ Subject: Re: Initializing Global Objects Message-ID: <675518012.60@sunbrk.FidoNet> Date: 28 May 91 18:33:12 GMT Sender: Usenet@sunbrk.FidoNet.Org Lines: 32 Reply-To: comeau@csanta.attmail.com (Greg Comeau) In article <76813@brunix.UUCP> sdm@cs.brown.edu (Scott Meyers) writes: :Section 3.4 of the ARM (pp. 20-21 of the American version) describes the :standard method for ensuring that a global object X is initialized before :it is used: put a static object inside each translation unit that can use :X, and have the constructor for the static object's class initialize X. :..My question concerns the static class variable that is used to determine :whether X has already been initialized. From the ARM: : class nifty_counter { static count; ... }; :We know that nifty_counter::count is preinitialized to 0 because it is :static, but the rules of the language also require that it be initialized :by the programmer somewhere. My question is this: to what value should it :be initialized? That is not quite accurate. We are told that it must be defined. Although that has an implicit initialization mandate, it's far from saying that the programmer must explicitely do it. Point in fact, is that defining it is the way you should do it (I'll go so far as to say that although the Iostream_init... = 0; example you raised will probably work almost all the time, it is not guaranteed from what I can see). So you raise a good point. - Greg -- Comeau Computing, 91-34 120th Street, Richmond Hill, NY, 11418 Producers of Comeau C++ 2.1 Here:attmail.com!csanta!comeau / BIX:comeau / CIS:72331,3421 Voice:718-945-0009 / Fax:718-441-2310 * Origin: Seaeast - Fidonet<->Usenet Gateway - sunbrk (1:343/15.0)