Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!rutgers!seismo!rochester!crowl From: crowl@rochester.ARPA (Lawrence Crowl) Newsgroups: net.lang.c++ Subject: Re: Implementing statics with constructors Message-ID: <22124@rochester.ARPA> Date: Tue, 4-Nov-86 10:56:08 EST Article-I.D.: rocheste.22124 Posted: Tue Nov 4 10:56:08 1986 Date-Received: Wed, 5-Nov-86 06:02:57 EST References: <5@dvm.UUCP> Reply-To: crowl@rochester.UUCP (Lawrence Crowl) Distribution: na Organization: U of Rochester, CS Dept, Rochester, NY Lines: 21 In article <5@dvm.UUCP> hymie@dvm.UUCP (Hyman Rosen) writes: )It is clear from the C++ book that static variables of types with )constructors are initialized by calls to the constructors at some )point before the call to main(). I would like to know how the )various implementations of C++ arrange for this to happen. It seems )to be difficult to do without a system of multiple code segments )(where all initialization code could be brought together). Other- )wise, I can only think of expensive "is this the first time?" )checking. The compiler generates a routine to call all of the static constructors within each individual source file. These routines have special names and are placed in the .o file. When the .o files are linked together, the names of the constructors (and destructors) are extracted and called from a routine created (sort of) at link time. It is this created routine that is called before main(). Because this model doesn't fit with the standard compiler and linker model, the details are kind of ugly. -- Lawrence Crowl 716-275-5766 University of Rochester crowl@rochester.arpa Computer Science Department ...!{allegra,decvax,seismo}!rochester!crowl Rochester, New York, 14627