Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!rutgers!columbia!select.columbia.edu!beshers From: beshers@select.columbia.edu (Clifford Beshers) Newsgroups: comp.lang.c++ Subject: Global constructors and C++ I/O streams; problems and questions. Message-ID: <5955@columbia.edu> Date: 20 Oct 88 01:15:54 GMT Sender: news@columbia.edu Reply-To: beshers@select.UUCP () Organization: Columbia University Department of Computer Science Lines: 46 The following program suffers a memory fault before it ever gets to the first line of main(). The problem lies in the constructor of the global instance 'example hello'; the reference to the cout stream occurs before the initialization of that stream. Because global instances are initialized in the order in which they are declared, this is expected; only external references to these streams are present in stream.h, and so their actual declaration gets packaged into libC.a. So, the question, is there any way around this? It seems like this would problem would exist for *any* class instances are declared in some library. Sure, I don't *really* need this feature, but it is nice. ***************************** Cut Here ******************* // The following code illustrates a problem with the interaction // of global constructors of user defined objects and with the // global constructors of system defined objects, namely standard // I/O streams. #include class example { public: example() { cout << "Hello, world\n"; } }; // Comment out this line and it works, of course. example hello; main() { cout << "We never get to the first line...\n"; } Cliff Beshers Columbia University Computer Science Department beshers@sylvester.cs.columbia.edu