Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!munnari!otc!mikem From: mikem@otc.oz (Mike Mowbray) Newsgroups: comp.lang.c++ Subject: Re: ordering of static constructors... Message-ID: <171@otc.oz> Date: Tue, 11-Aug-87 19:28:44 EDT Article-I.D.: otc.171 Posted: Tue Aug 11 19:28:44 1987 Date-Received: Fri, 14-Aug-87 05:00:50 EDT References: <2973@uw-june.UUCP> Distribution: world Organization: OTC Development Unit, Australia Lines: 49 In article <2973@uw-june.UUCP>, brian@uw-june.UUCP (Brian Bershad) says: > > What's the best way (is there a way) to specify the order in which > one's static constructors are called? You can't do it manually. > I am trying to use ostream from within a constructor X, but the need > for an ostream constructor is getting picked up by munch after the need > for my static constructor X is found. The result: > segmentation violation > in X. > > This is version 1.2, and it passes the static test cases that > come with the distribution. We have implemented a simple change to munch.c which fixes up most of these problems. The trouble is that munch normally takes ctors in the right order, but arranges for them to be called in the reverse order. (This is correct for dtors.) This isn't guaranteed to work everywhere all the time, but if you lorder & tsort your library modules, etc, it should be okay. Here are the diff's to lib/static/munch.c : < sbuf* dtor; // list of constructors < sbuf* ctor; // list of destructors --- > sbuf* dtor; // list of destructors > sbuf* ctor; // list of constructors > sbuf* tail; // tail of list of constructors 63c64,69 < ctor = new sbuf(ctor,st); --- > register sbuf *newctor = new sbuf(NULL, st); > if (tail != NULL) > tail->next = newctor; > else > ctor = newctor; > tail = newctor; Mike Mowbray Systems Development |||| OTC || ACSnet: mikem@otc.oz UUCP: {uunet,mcvax}!otc.oz!mikem Phone: (02) 287-4104 Snail: GPO Box 7000, Sydney 2001, Australia