🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

initializing several translation units

#1357
From: Hendrik Boom
Date: Fri, 22 Jan 1993 15:24
48 lines
1910 bytes
---------------
Translation unit 1:

class x{....
	x();
	....};

extern x y;

foo(){ .... y ....}

Translation unit 2:

class x{....
	x();
	....};
	// same class x as above; presumably both are really in a header file

x y;

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

Can I rely on y being initialized in translation unit 2 by
the constructor x::x() before it is used in translation unit 1?
-- Assuming there is no other dependency of unit 2 on unit 1, of course.

The ARM (section 3.4, page 19) suggests in large print that you can:
	The initialization of nonlocal static objects in a translation
	unit is done before the first use of any function or object
	defined in that translation uniot.

So the initialization of y in unit 2 should occur before any use of y,
which is defined in unit 2. The ARM doesn't say that the use has to be
in unit 1.

The ARM then proceeds undercut this in the small print by suggesting ways
you can accomplish proper initialization order by long, complicated coding.
Is the small print an advice to the implementer (in which case the user
can rely on proper initialization of y) or advice to the user
(in which he can't)?

Is the situation different if foo() is called from the initializer of
another nonlocal static object in unit 1?
-- 
-------------------------------------------------------
Try one or more of the following addresses to reply.
at work:	hendrik@vedge.com,  iros1!vedge!hendrik
at home:	uunet!ozrout!topoi!hendrik
Technical Details
Message-ID: <1993Jan22.152436.5221@vedge.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!gatech!paladin.american.edu!howland.reston.ans.net!usc!cs.utexas.edu!sun-barr!olivea!charnel!sifon!thunder.mcrcim.mcgill.edu!sobeco!philmtl!vedge!hendrik

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!gatech!paladin.american.edu!howland.reston.ans.net!usc!cs.utexas.edu!sun-barr!olivea!charnel!sifon!thunder.mcrcim.mcgill.edu!sobeco!philmtl!vedge!hendrik
From: hendrik@vedge.com (Hendrik Boom)
Newsgroups: comp.std.c++
Subject: initializing several translation units
Message-ID: <1993Jan22.152436.5221@vedge.com>
Date: 22 Jan 93 15:24:36 GMT
Organization: Visual Edge Software Ltd.
Lines: 48