mercredi 16 avril 2014

Linux - C++, les variables globales et les bibliothèques partagées dynamiques - Stack Overflow


globals are bad I know, but even statics local to a function appear to be bad.


I noticed that on linux, globals and statics inside a shared object (dynamic library) are initialised the first time you use dlopen. But when you dlclose, and then dlopen again, it doesn't initialise globals or statics the second time.


This isn't the same as windows: http://msdn.microsoft.com/en-us/library/988ye33t.aspx Which I've tested and does appear to re-initialise statics.


Is this true, or am I just messing something else up?


If this is true, wouldn't this make any kind of static variable dangerous/useless?



globals are bad I know, but even statics local to a function appear to be bad.


I noticed that on linux, globals and statics inside a shared object (dynamic library) are initialised the first time you use dlopen. But when you dlclose, and then dlopen again, it doesn't initialise globals or statics the second time.


This isn't the same as windows: http://msdn.microsoft.com/en-us/library/988ye33t.aspx Which I've tested and does appear to re-initialise statics.


Is this true, or am I just messing something else up?


If this is true, wouldn't this make any kind of static variable dangerous/useless?


0 commentaires:

Enregistrer un commentaire