Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!killer!ames!amdcad!sun!pitstop!sundc!seismo!uunet!mcvax!cernvax!ethz!iis!prl From: prl@iis.UUCP (Peter Lamb) Newsgroups: comp.lang.c++ Subject: Re: Summary of global constructor responses. Message-ID: <658@eiger.iis.UUCP> Date: 26 Oct 88 18:51:38 GMT References: <5964@columbia.edu> Reply-To: prl@iis.UUCP (Peter Lamb) Organization: Integrated Systems Lab., ETH Zuerich Lines: 50 In article <5964@columbia.edu> beshers@select.UUCP (Jonathan M. Smith) writes: >I got several responses to my query about the calling order of global >constructors. Since it seems to be and important issue, I provide >a summary here. ... > The AT&T compiler chooses to order the invocations >back-to-front, i.e. the modules or libraries later in the command >line are called before those earlier. (That is, with the above >patch applied.) > It may be a little counter-intuitive, but *DONT* go changing the order of the way in which munch generates it's table of constructor pointers. The constructors in libraries should get called *FIRST* (this is the problem that you were having in the first place - they weren't getting called first) Since libraries are usually somewhere down the righthand end of the load CC, their constructors need to be called before main's constructor. (This is assuming the nm command outputs the symbols for the earliest-loaded symbols first in its listing) Note: Mike Mobray, who usually gets such things right also posted a `fix' for munch to reverse the order of call of the static constructors. Don't do this in AT&T 1.2.1 C++. Munch does the right thing there. The right fix is to use nm -p (output the symbols in loader order) or nm -n (output the symbols in numerical order) in the CC script. > Since the problem seems very system and loader dependent, >there is not formal specification in the language. The best we >can expect is that all compilers document their ordering methods >clearly. True, and sadly this is typically not documented. Neither is the order in which constructors for member objects are called. (at least not in the first edition of the book) > >Cliff Beshers >Columbia University Computer Science Department >beshers@sylvester.cs.columbia.edu -- Peter Lamb uucp: uunet!mcvax!ethz!prl eunet: prl@ethz.uucp Tel: +411 256 5241 Integrated Ststems Laboratory ETH-Zentrum, 8092 Zurich