🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2099

Re: Static objects initialization before main()

#2099
From: MichaelFurman
Date: Mon, 02 Oct 1995 16:14
82 lines
4298 bytes
In article <44j7pn$ca9@oznet07.ozemail.com.au>,
John Max Skaller <maxtal@suphys.physics.su.oz.au> wrote:

>engr@gssi.MV.COM (MichaelFurman) wrote:
>>   Reading some answers in C++ newsgroups and ARM I found that feature that
>>I am using is not supported by C++ draft standard. I rely on fact that all
>>static class instances in the program will be initialized (by calling
>>appropriate constructors) before executing "main" function. I do not know
>>how to implement what I want (see below) without it.
>[]
>>   If initialization can be "deferred to any point in time before the first
>>use a function or object defined in that translation unit" (as described in
>>ARM and I believe - I do not have it with me - in draft standard) - I can
>>not implement this strategy at all because in main part of software I do not
>>know which translation units - drivers - I have. It seams to me that I can
>>not avoid recompilation of some file and I have to change that file each
>>time I implement a new driver.
>
>   Not true. You cannot implement PORTABLE code that way. You CAN
>rely on a particular compiler though.

Either I can rely on another language e. t. c. 
Seriously, of cause, in my particular program I am relying on compiler(s) 
I have and I do not think I will have a trouble in nearest future. But reason
of my post is not a solving my problem, but discussing features of C++.

> If you are implementing
>device drivers, this might not be so much of a problem.

It is not necessary device drivers - they may be modules of any expandable
system. 

>
>>
>>My questions:
>>
>>1. What is a reason of allowing it to be deferred.
>
>     Dynamic Link Libraries.
>
>>2. May be I just don't see how to implement it better, without relying on
>>this unsupported fact (actually all compilers I know do it before calling
main)
>.
>
>     The correct way to implement it requires writing an initialisation
>module which DOES know what drivers are to be supplied. To avoid
>writing it out by hand all the time, write a program to generate
>this initialisation function from information obtained somehow
>from a specication file describing the available drivers.

The problem is that is no portable form of such specification file 
(it may be only input data for linker or executable program file). And there
is no portable way to do something with this information. And it is 
nothing with C++. 
>
>>3. If not - may be it is possible to consider changing the standard.
>
>    This topic has been discussed many times: the current situation
>is not entirely satisfactory. Unfortunately, any solution appears
>to require a language extension.

Yes, I understand it. But all we need - just to mark somehow definitions
of objects that has to be initialized before executing "main". May be some 
existant language attribute can be used? Global scope? No - it would prevent
optimisation based on virtual memory. "Const"? Do anybody have an idea?

        Regards,
                        Michael Furman
----------------------------------------------------------------------------
--------
Michael Furman,                                   (603)893-1109
Geophysical Survey Systems, Inc.              fax:(603)889-3984
13 Klein Drive - P.O. Box 97                      engr@gssi.mv.com 
North Salem, NH 03073-0097                        71543.1334@compuserve.com
----------------------------------------------------------------------------
--------


[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <199510021604.MAA10538@mv.mv.com>
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage
From: engr@gssi.MV.COM (MichaelFurman)
Newsgroups: comp.std.c++
Subject: Re: Static objects initialization before main()
Date: 2 Oct 1995 16:14:19 GMT
Organization: ?
Approved: clamage@eng.sun.com (comp.std.c++)
Message-ID: <199510021604.MAA10538@mv.mv.com>
NNTP-Posting-Host: taumet.eng.sun.com
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
X-Sender: gssi-en@mv.mv.com (Unverified)
X-Mailer: Windows Eudora Version 1.4.3
X-Lines: 78
Content-Length: 3439
Originator: clamage@taumet