From: Roy S. <roy...@ic...> - 2013-04-03 17:04:09
|
On Wed, 3 Apr 2013, Derek Gaston wrote: > It's simply not possible Roy. The code to do the push_back is in > the same .C file with the thing it's trying to push_back on. Right. Which doesn't matter. C++ guarantees that two static objects declared in the same file will be initialized in the order of declaration, but it absolutely does not guarantee that a static object declared in a file will be initialized before any object in any other file calls any method in the first file. > If you > can't count on statics in the same .C file being created before you > try to use them.... then we're all screwed! This is actually not too hard to fix. We just use the "Construct on First Use" idiom for the containers. I'll demonstrate with a patch shortly. > That static will get created when the translation unit is loaded to > run Singleton::Setup::Setup() (if not before then). No, it really really won't. There is no "interrupt one constructor to run another just-in-time" code in C++. --- Roy |