Topic: initializing several translation units


Author: hendrik@vedge.com (Hendrik Boom)
Date: 22 Jan 93 15:24:36 GMT
Raw View
---------------
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