Hi Petr,
* 1st: All static objects are initialized to zero.
* 2nd: Static objects of intrinsic/primitive types initialized with constant expressions are initialized.
* Static objects of namespace scope defined in the same translation unit are initialized in the order that their definitions appear in the translation unit.
Do static objects of class scope belong to the objects of namespace scope?
And I assume that 1. and 2. are initialized throughout the whole binary, not individual translation units only. right?
No, I think it won’t always work (see my first comment). I’ve tested it in the PeerInfo class - it’s ctor is first called in the TrackerRequestSessionTest.cpp:197 (that’s compiler dependant) and it’s data were not initialized at that moment (recieved segfault).
I see.
So, I’d suggest to try creating only intrinsic/primitive (where it’s possible) static constants (in classes/namespaces, excluded tests). Where it won’t be possible (and can make problems), we can still use some more tricky solution like Schwarz counters, but lets first try to use the former solution.
Do you mean not to use static members in tests? You actually already suggested before that we initialize complex objects in the Test class ctor - that seems like the only solution.
Regards,
Peter
