Article View: comp.std.c++
Article #2080Re: Static objects initialization before main()
From: John Max Skaller
Date: Sat, 30 Sep 1995 19:07
Date: Sat, 30 Sep 1995 19:07
56 lines
2820 bytes
2820 bytes
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. If you are implementing
device drivers, this might not be so much of a problem.
>
>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.
>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.
--
John Max Skaller voice: 61-2-566-2189
81 Glebe Point Rd fax: 61-2-660-0850
GLEBE NSW 2037 email: maxtal@suphys.physics.oz.au
AUSTRALIA email: skaller@maxtal.com.au
---
[ 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:
<44j7pn$ca9@oznet07.ozemail.com.au>Path:
arc1-ca.pugleaf.net!howland.reston.ans.net!agate!agate!MattReferences:
<199509282107.RAA13781@mv.mv.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!howland.reston.ans.net!agate!agate!Matt From: John Max Skaller <maxtal@suphys.physics.su.oz.au> Newsgroups: comp.std.c++ Subject: Re: Static objects initialization before main() Date: 30 Sep 1995 19:07:55 GMT Organization: MAXTAL Approved: Matt@Austern Message-ID: <44j7pn$ca9@oznet07.ozemail.com.au> References: <199509282107.RAA13781@mv.mv.com> NNTP-Posting-Host: austern.hip.berkeley.edu