🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Hendrik Boom Fri, 22 Jan 1993 15:24
initializing several translation units
#1357
Author: 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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads