Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!columbia!rutgers!husc6!hao!boulder!sanders From: sanders@boulder.Colorado.EDU (Bruce Sanders) Newsgroups: comp.lang.c++ Subject: Is this a bug? Message-ID: <731@boulder.Colorado.EDU> Date: Thu, 11-Jun-87 13:08:13 EDT Article-I.D.: boulder.731 Posted: Thu Jun 11 13:08:13 1987 Date-Received: Sat, 20-Jun-87 10:19:38 EDT Organization: University of Colorado, Boulder Lines: 71 Keywords: streams, bug, global constructors 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(); } // ---------------------------------------------------------------------------- adb gives the following output: % adb a.out core file = core -- program ``a.out'' SIGSEGV 11: segmentation violation $c __ostream__lshiftFPC__(0x20d60,0x20071) + 30 __STIjnk_c_() + 24 __main() + 14 _main(0x1,0xefffbbc,0xefffbc4) + e If I comment out the two lines with "global" in them, everything works, producing the following output: % a.out constructor local constructor static local static Alternatively, if I remove the cerr and print statements (indicated in the comment) from the constructor, it works correctly, producing % a.out global local static Is this a bug, or am I doing something illegal? thanks bruce Bruce W. Sanders Department of Computer Science University of Colorado Campus Box 430 Boulder, CO 80309-0430 (303) 492-8118 sanders@boulder