Topic: Global object initialization again


Author: "Eugene Radchenko" <eugene@qsar.chem.msu.su>
Date: 1995/10/06
Raw View
Hello people!
I would like to learn more about the proposal by German ISO representative
allowing (partial) programmer control of the inter-file initialization
order. This would be a very useful feature, especially in designs where you
need some server object in one module to be initialized before other
modules can access it.

Schwartz counters help here, but there are the situations where they are
insufficient. E.g. server initialization in module A calls the function
which dynamically selects the type of server object, creates it (using
new) and returns the pointer. For some types, it needs to access another
server from module B. But there is no way (short of #including B-module
header in A-module header where it is otherwise unnecessary) to ensure that
B-server gets initialized prior to A-server.

Techniques relying on static zero-initialization and/or local static
objects initialized upon function entry also do not solve the problem, as
servers requiring non-trivial init often need non-trivial shutdown as well
- in exactly the same environment. While my compiler (BC++ 4.0) at least
does strange things to order of local static objects cleanup.

            Best regards                        Genie

--
--------------------------------------------------------------------
Eugene V. Radchenko           Graduate Student in Computer Chemistry
E-mail: eugene@qsar.chem.msu.su                Fax: +7-(095)939-0290
Ordinary mail:  Chair of Organic Chemistry, Department of Chemistry,
                      Moscow State University, 119899 Moscow, Russia
*****************  Disappearances are deceptive  *******************
---
[ 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. ]





Author: Kalyan Kolachala <kalyan@taligent.com>
Date: 1995/10/07
Raw View
A related and more intractable problem is that of the order of
initialization of statics in template classes. There is simply no
solution as there is no way of knowing what type the template class
will be instantiated with.

The only workaround I know of is not to use static data members in
template and instead put the statics within a member function.

I was wondering if there is any solution for this in the proposed
template compilation model.

Thanks,
Kalyan
---
[ 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. ]