Re: PeerInfo and PeerId

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

Would you like to post a relpy?


This post is a reply to:
Re: PeerInfo and PeerId
Hi Peter, I was thinking that we could also provide a named ctor fromUri() to complement the toUri() function. Sure - good idea. I'll add it. Regarding the static initialization dependency, does it (more...)

Follow-ups:
Re: PeerInfo and PeerId
Hi Peter, Do static objects of class scope belong to the objects of namespace scope? I thought so at first (class can be considered as a namespace from my point of view), (more...)