Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!att!ulysses!andante!alice!ark From: ark@alice.UUCP (Andrew Koenig) Newsgroups: comp.lang.c++ Subject: Re: Help! Keywords: constructors, C++ i/o, extern Message-ID: <9573@alice.UUCP> Date: 7 Jul 89 04:04:21 GMT References: <2774@ssc-vax.UUCP> <4443be62.1ad5a@apollo.COM> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 33 In article <4443be62.1ad5a@apollo.COM>, vasta@apollo.COM (John Vasta) writes: > The cout object from the stream library must be initialized when the > program starts up. So does your myjunk object. The order of execution > of constructors for static objects in different modules is not defined. C++ 2.0 does two things to make this less of a bother. First, the 2.0 stream library goes to some trouble to ensure that it works correctly even in the face of static constructors and destructors. Second, if you have a static object that is local to a function, that object will be initialized no later than the first time that the flow of control passes through that declaration, even if that function is called from a static constructor. Example: struct T { T(); }; void f() { static T t; }; In this example, T::T() will be called to initialize t no later than the first time f() is executed. -- --Andrew Koenig ark@europa.att.com