Normally using a variable in a .cpp file results in the variable being globally available, like this:
.h file:
extern int myGlobal;
void work();
.cpp file:
int myGlobal = 42;
void work(){ myGlobal++; }
When the .cpp file is put in a static library and more than one shared library (DLL) or executable links against the static library, each one has its own copy of myGlobal
. work() would modify its own version of the variable.
My question now: is there a way to get a process-wide unique variable or pointer to that variable? Similar what thread-local storage would be for thread-wide variables. It doesn't have to be platform independent. Bonus points if it works in Win32 :)