Consider the case of a class member function defined in a header, with a static
storage variable. When you include the header in multiple compilation units, you will end up with multiple copies of the static
variable. However, the compiler will fix this for you, and just pick one of the emitted variables (note that this is different from inlining). This is enabled by a GNU specific extension to the possible types of a symbol, precisely gnu_unique_object
(they show up as "u" in nm
, which calls them in the man pages "unique global symbols").
The question is, how do you force the compiler to produce this kind of symbols for arbitrary variables? I'm tired of wrapping things in a class to get this behavior.