C ++ static global non-POD: theory and practice

I read the Qt coding standards docs and came to the following paragraph:

Everything that has a constructor or should run the code that needs to be initialized, cannot be used as a global object in the library code, since it is undefined when this constructor / code is run (at first use, when loading the library before main () or not at all ). Even if the initializer runtime is defined for shared libraries, you will encounter a problem when moving this code in the plugin or when building the library statically.

I know what the theory is talking about, but I don’t understand "not at all." Sometimes I use non-POD global const statics (like QString), and it never occurred to me that they cannot be initialized ... Is this specific to common DLL objects / libraries? Does this only happen to broken compilers?

What do you think of this rule?

+5
source share
5 answers

The β€œnot at all” part simply says that the C ++ standard is silent about this problem. He does not know about shared libraries and, thus, does not say anything about the interaction of some C ++ functions with them.

-POD , Windows, OSX Linux Unices, , , . , ( -POD) . , - , , GCC , dtors , , . , ( , ), .

, , .

+8

, . , , , , . , , , . ( , , , ).

+2

, , , . libs (, libc gnu, .).

, , . , .

+2

.

( ).

, , , , .

, ( , ) , , ( , ) ++ , .

.

+2

++ , ( ).

, 2 A B, . , B A .

, B A. , " " - , ( ).

, , , cuase . , , , , , , .

+2
source

All Articles