Path: utzoo!utgpu!water!watmath!clyde!rutgers!ames!amdcad!sun!pitstop!sundc!seismo!uunet!mcvax!cernvax!hslrswi!robert From: robert@hslrswi.UUCP (J. Robert Ward) Newsgroups: comp.lang.c++ Subject: Re: Ordering of initialisation of static classes in *different* files ? Keywords: ordering of static initialisation Message-ID: <735@hslrswi.UUCP> Date: 19 Jan 88 10:44:36 GMT References: <734@hslrswi.UUCP> <218@goofy.megatest.UUCP> Reply-To: robert@hslrswi.UUCP (J. Robert Ward) Organization: Hasler AG, CH-3000 Berne 14, Switzerland Lines: 45 The story so far - here is my starting comment: >> It seems to me that there is a (small) defect in the definition of >> the C++ language. Namely, the order in which static objects are >> initialised is apparently undefined when more than one source file >> is under consideration. In article <218@goofy.megatest.UUCP> djones@megatest.UUCP (Dave Jones) writes: > >On page 289, it says "Constructors for non-local static objects are called >in the order they occur in a file...". I find nothing about ordering >of constructor calls for objects declared in separate files. A little >thought will convince you that it would be a non-trivial job to assure >proper order of construction. I agree that this is decidedly a "non-trivial job". However, it seems to me that guaranteed ordering of initialisation is required if one wants to write self-contained and independent modules that themselves use objects from other libraries. I think my example of cout not being properly initialised in good time illustrates this. As Dave Jones points out, it is possible to work around this problem *in this example*, but surely I shouldn't have to resort to such subterfuge. And besides, who says such work arounds are always available ? At the risk of being mercilessly flamed (no religious wars here, please!) I wish to point out that this problem is solved in Modula-2 so that modules relying on other objects being properly initialised can indeed do so (this is about the only good thing M2 has going for it, but that's a different story). Any further comments ? Cheers, - R. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ J. Robert Ward, ___________ Hasler AG, Belpstrasse 23, CH-3000 Berne 14, Switzerland | _ | | _| |_ | Tel.: +41 31 633922 | |_ _| | X.400: robert@hslrswi.hasler | |_| | Bitnet: robert%hslrswi.UUCP@cernvax.BITNET |_________| Uucp: ... {uunet,ukc,mcvax ... }!cernvax!hslrswi!robert ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~