
2011/9/1 Julien Nitard <julien.nitard@m4tp.org>
It can't, you will end up with a different function static variable for each translation unit.
This isn't the case. If you have an inline function with a static
variable
in it, it'll be the same variable in all translation units.
*7.1.2p4 A static local variable in an extern inline function always refers to the same object.*
... which I guess means you can still end up with several definitions when using dynamic libraries ?
If they don't export the function properly, then yes. By messing with the set of exported symbols in shared libraries one can end up with all sorts of anomalies: failure to dynamic_cast std::string to std::string, or failure to catch exceptions even when the type of the exception thrown is the same as the type of the exception in the catch clause. If I wanted to guarantee that there is exactly one instance of the variable regardless of the symbol export map, I'd put the variable in a shared library. Roman Perepelitsa.