Is the static statics of the class template created differently in shared libraries consistent in the final binary format?

I have several classes that act as a unique type identifier generator:

// <type_generator.hpp>
template<typename SK,typename T>
struct Component
{
    static uint const index;
};

template<typename SK>
class ComponentCount
{
    template<typename CSK,typename CT>
    friend struct Component;

private:
    template<typename T>
    static uint next() {
        return ComponentCount<SK>::get_counter();
    }

    static uint get_counter()
    {
        static uint counter = 0;
        return counter++;
    }
};

template<typename SK,typename T>
uint const Component<SK,T>::index(ComponentCount<SK>::template next<T>());

struct Key{};

Now say that I create the above class templates in different ways in several different libraries:

// libsrc0
uint const x0 = Component<Key,int>::index;
uint const x1 = Component<Key,std::string>::index;
uint const x2 = Component<Key,double>::index;

// libsrc1
uint const x0 = Component<Key,std::string>::index;
uint const x1 = Component<Key,double>::index;
uint const x2 = Component<Key,int>::index;

// libsrc2
uint const x0 = Component<Key,int>::index;
uint const x1 = Component<Key,std::string>::index;

Is there any guarantee that a binary that references libsrc0, libsrc1 and libsrc2 will have a sequential definition of the Component :: index indices, with each index having a different value?

Component<Key,int>::index
Component<Key,std::string>::index
Component<Key,double>::index
+4
source share
1 answer

- , , libsrc0, libsrc1 libsrc2, Component:: index?

. , , . . , , .

, Component , , Component::index, . , , GNU Linux , , -l , , , .

+3

Source: https://habr.com/ru/post/1674899/


All Articles