🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by Hyman Rosen Tue, 04 Nov 1986 02:22
Implementing statics with constructors
#378
Author: Hyman Rosen
Date: Tue, 04 Nov 1986 02:22
15 lines
1050 bytes
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.
-- 


								- Hymie

		...{decvax,ihnp4,ucbvax}!allegra!phri!orville!dvm!hymie
Re: Implementing statics with constructors
#379
Author: Lawrence Crowl
Date: Tue, 04 Nov 1986 15:56
21 lines
1813 bytes
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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads