Topic: [basic.start.init] 3.6.2 Initialization of nonlocal objects


Author: Raoul De Kezel <raoul.de.kezel@infoboard.be>
Date: 1995/06/17
Raw View
maxtal@Physics.usyd.edu.au (John Max Skaller) wrote:
> As a result of a previous posting to comp.std.c++ I
>posted an article to the committee core reflector in which I proposed
>the wording of 3.6.2 be changes -- it is a seriously faulty
>clause.
>
> The change I propose is something like:
>
>1 * The initialization of nonlocal objects with static storage
>duration (3.7) defined in a translation unit
>__shall be done by the implementor__ before the
>first use of any function or object defined in that translation
>unit __directly in the dynamic scope of main; that is,
>a use by an initialiser of a non-local static object
>is exempt from this requirement__.

I hope that the rewording will be accepted, so as not to give
false hopes to the programmer while promising the impossible.


>The point of the rewording is to make it clear it is NOT
>the implementors responsbility to do any kind of initialisation
>dependency checking. Any implementation which sequentially
>initialises each non-local variable, for each translation
>unit in any order, just prior to main being called, is conforming.

I hope that everybody understands that "*shall* be done" means that
the programmer who wants to take over the responsability of
initialization ordering is going to have a hard work because the
mandatory but otherwise mostly unconstrained implementation
initiated initialization can't be disabled.

--- Raoul De Kezel








Author: maxtal@Physics.usyd.edu.au (John Max Skaller)
Date: 1995/06/15
Raw View
In article <3rim5b$etv@news.erinet.com>,
Paul J. Ste. Marie <pstemari@erinet.com> wrote:
>The draft standard reads:
>
>>>>>>
>[basic.start.init] 3.6.2 Initialization of non   local objects
>
>1 * The initialization of nonlocal objects with static storage
>duration (3.7) defined in a translation unit is done before the
>first use of any function or object defined in that translation
>unit. Such initializations (8.5, 9.5, 12.1, 12.6.1) can be done
>before the first statement of main() or deferred to any point in
>time before the first use of a function or object defined in that
>     ^^^^^^^^^^^^^^^^^^^^^^^            ^^^^^^^^^
>translation unit.
>>>>>>
>
>I've asked before--I'll ask again.  What constitutes the "use of an
>object"?

 1) calling a non-static member function on it
 2) taking its address or binding a reference to it -- sometimes
 3) for scalar types -- loading its value or store a value in it

>initialized before foo is.  Has the committee really bitten this
>bullet, or are things as flaky as they ever where?  If not, the
>section requires rewording.

 As a result of a previous posting to comp.std.c++ I
posted an article to the committee core reflector in which I proposed
the wording of 3.6.2 be changes -- it is a seriously faulty
clause.

 The change I propose is something like:

1 * The initialization of nonlocal objects with static storage
duration (3.7) defined in a translation unit
__shall be done by the implementor__ before the
first use of any function or object defined in that translation
unit __directly in the dynamic scope of main; that is,
a use by an initialiser of a non-local static object
is exempt from this requirement__.

The point of the rewording is to make it clear it is NOT
the implementors responsbility to do any kind of initialisation
dependency checking. Any implementation which sequentially
initialises each non-local variable, for each translation
unit in any order, just prior to main being called, is conforming.
(I hope you can parse this English as I intend)

It is up to the programmer to ensure this will always work;
it is the __programmers__ error if an uninitialised object is used
during the initialisation processes. (Provided the compiler
does other things right of course)

An implementation _may_ delay initialisation, however, provided
the semantics are "equivalent" (other than the timing).
In particular initialising a unit which is embodied in
a DLL at the time of loading is permitted.

--
        JOHN (MAX) SKALLER,         INTERNET:maxtal@suphys.physics.su.oz.au
 Maxtal Pty Ltd,
        81A Glebe Point Rd, GLEBE   Mem: SA IT/9/22,SC22/WG21
        NSW 2037, AUSTRALIA     Phone: 61-2-566-2189





Author: pstemari@erinet.com (Paul J. Ste. Marie)
Date: 1995/06/13
Raw View
The draft standard reads:

>>>>>
[basic.start.init] 3.6.2 Initialization of non   local objects

1 * The initialization of nonlocal objects with static storage
duration (3.7) defined in a translation unit is done before the
first use of any function or object defined in that translation
unit. Such initializations (8.5, 9.5, 12.1, 12.6.1) can be done
before the first statement of main() or deferred to any point in
time before the first use of a function or object defined in that
     ^^^^^^^^^^^^^^^^^^^^^^^            ^^^^^^^^^
translation unit.
>>>>>

I've asked before--I'll ask again.  What constitutes the "use of an
object"?  Historically, using an object outside a translation unit
in a initializer for an object of static storage duration has not
worked--eg in:

file1.cpp----

// suitable declarations of OtherObject and its class

int foo = OtherObject.somefunc();

file2.cpp----

// suitable declarations of OtherObject and its class

SomeClass OtherObject;

-------------

OtherObject has not been guaranteed to be initialized before foo.
Now, to me, it seems that OtherObject.somefunc() is a use of
OtherObject, and the underlined line in the WP requires that it be
initialized before foo is.  Has the committee really bitten this
bullet, or are things as flaky as they ever where?  If not, the
section requires rewording.

 --Paul J. Ste. Marie, pstemari@well.sf.ca.us, pstemari@erinet.com

Contact your Senators today to oppose the Comunications Decency Act
(S.652, Title IV)!