🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Static objects initialization before main()

#2105
From: Pulkkinen Esa
Date: Tue, 03 Oct 1995 18:19
34 lines
2111 bytes
In article <199510021604.MAA10538@mv.mv.com>,
MichaelFurman <engr@gssi.MV.COM> wrote:
>
>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?
>
I once thought marking an object volatile would do the trick.
Since as the DWP states ([dcl.type.cv]/7) volatile is meant to disallow
a set of optimizations for the use of the object. When an object is
volatile, the compiler shouldn't make any assumptions about when
the object's value is changed. Thus, since the compiler 
can't know when the object's value is changed, it can't rely it
being initialized when the first use of the object is made 
[basic.start.init]/1  (perhaps in an interrupt etc), except if it 
initializes the object before main(). Of course this applies only to
volatile objects with static storage duration and user defined
constructor.

I understand this isn't perhaps what volatile is meant for (the DWP says
it should work "as in C"), but it certainly fits with my
view of how volatile should work.
-- 
   Esa Pulkkinen                        | C++ programmers do it virtually
   E-Mail:  esap@cs.tut.fi              | everywhere with a class, resulting
   WWW   :  http://www.cs.tut.fi/~esap/ | in multiple inheritance.


---
[ 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: <44rrsp$r59@peippo.cs.tut.fi>
Path: arc1-ca.pugleaf.net!128.32.155.1!matt
References: <199510021604.MAA10538@mv.mv.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!128.32.155.1!matt
From: esap@cs.tut.fi (Pulkkinen Esa)
Newsgroups: comp.std.c++
Subject: Re: Static objects initialization before main()
Date: 03 Oct 1995 18:19:59 GMT
Organization: Tampere University of Technology
Approved: matt@physics2.Berkeley.EDU (Matt Austern)
Message-ID: <44rrsp$r59@peippo.cs.tut.fi>
References: <199510021604.MAA10538@mv.mv.com>
NNTP-Posting-Host: physics2.berkeley.edu