I am wondering what exactly the difference between the following two declarations is if both are written in a single header file:
inline thread_local MyClass obj1; // inline with thread_local
thread_local MyClass obj2; // no inline
As specified in C++17, adding inline to a variable forces all translation units to see the same address of that variable. Does this mean it's possible for obj2
to get different address values in different translation units? What would be the situation to highlight we should use obj1
rather than obj2
?