Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!husc6!rutgers!princeton!allegra!alice!ark From: ark@alice.UUCP Newsgroups: comp.lang.c++ Subject: Re: Is this a bug? Message-ID: <6978@alice.UUCP> Date: Fri, 12-Jun-87 01:06:10 EDT Article-I.D.: alice.6978 Posted: Fri Jun 12 01:06:10 1987 Date-Received: Sat, 20-Jun-87 13:40:29 EDT References: <731@boulder.Colorado.EDU> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 34 Keywords: streams, bug, global constructors In article <731@boulder.Colorado.EDU>, sanders@boulder.UUCP writes: -> -> When I compile and run the following C++ program, I get a segmentation fault. -> C++ version <> -> Sun OS version 3.3 -> -> // ---------------------------------------------------------------------------- -> #include -> -> class c { -> char *s; -> public: -> c(char *string) { s = string; cerr << "constructor "; print(); } -> // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -> void print() { cerr << s << "\n"; } -> }; -> -> c global("global"); -> -> main() -> { -> c local("local"); -> c stat("static"); -> global.print(); -> local.print(); -> stat.print(); -> } It looks like what is happening is that the constructor for the variable "global" is trying to print stuff before the I/O library is initialized. This is not a bug. The stream library relies on static constructors for its initialization, and there is no guarantee that static constructors will be executed in any particular sequence.