Xref: utzoo comp.sys.apollo:9551 comp.lang.c++:14356 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!caen!spool.mu.edu!munnari.oz.au!metro!usage.csd.unsw.oz.au!spectrum!ashley From: ashley@usage.csd.oz (Ashley Aitken) Newsgroups: comp.sys.apollo,comp.lang.c++ Subject: Is this a bug in Apollo C++ Compiler System? Message-ID: <1801@usage.csd.unsw.oz.au> Date: 25 Jun 91 03:19:36 GMT Article-I.D.: usage.1801 Sender: news@usage.csd.unsw.oz.au Reply-To: ashley@spectrum.cs.unsw.oz.au (Ashley Aitken) Followup-To: comp.sys.apollo Organization: University of New South Wales (EECS) Lines: 167 C++ Compiler System Bug Report? =============================== Overview: Not all constructors and destructors for global (and static) objects (in separated source files) are called before the start of the main program. Those called depend on the order of linking of the object files. Cause? I believe that the error is caused by failure of the start- up initialization code in the _entry routine, or more likely failure of the Constructor Linker. Technical: On observation of the C code generated it seems that the correct STI and STD functions and LINK structures are being created for each file but not being linked together or called correctly. c++patch / mxx ? Compiler: Error seems to be common to both Version 1.2.1 and Version 2.0 of the C++ Compiler (Glockenspiel) on HP-Apollo Domain machines. ld : C Compilation System, Issue 4.0 (11.0) 1/3/86 : Version 1.8.2.1: 11/19/85 Example Source Files (appended to document): file1.cxx file2.cxx Compilation: CC -c file1.cxx CC -c file2.cxx CC -o testa file1.o file2.o Output From testa: Construtor C Construtor D Start Main A::m1 Construtor B D::m1 End Main Destructor B Destructor D Destructor C Constructor (and Destructor) for a of class A is not called at all! CC -o testa file2.o file1.o Output from testb: Construtor A Start Main A::m1 Construtor B D::m1 End Main Destructor B Destructor A Constructor (and Destructor) for c of class C and d of class D are not called at all! file1.cxx: #include class A { public: A(); void m1(); ~A(); }; A::A() { cout << "Construtor A\n"; } void A::m1() { cout << "A::m1\n"; } A::~A() { cout << "Destructor A\n"; } A a; class B { public: B(); ~B(); }; B::B() { cout << "Construtor B\n"; } B::~B() { cout << "Destructor B\n"; } class D { public: D(); void m1(); ~D(); }; extern D d; main () { cout << "Start Main\n"; a.m1(); B b; d.m1(); cout << "End Main\n"; } *EOF* file2.cxx: #include class C { public: C(); ~C(); }; C::C() { cout << "Construtor C\n"; } C::~C() { cout << "Destructor C\n"; } static C c; class D { public: D(); void m1(); ~D(); }; D::D() { cout << "Construtor D\n"; } void D::m1() { cout << "D::m1\n"; } D::~D() { cout << "Destructor D\n"; } D d; *EOF* Originator: Ashley Aitken School of Electrical Engineering and Computer Science University of New South Wales ashley@spectrum.cs.unsw.oz.au Ph (02) 663-8117 (Answering) 24th June, 1991.