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

后端 未结 5 937
不思量自难忘°
不思量自难忘° 2021-02-15 02:11

I was reading the Qt coding conventions docs and came upon the following paragraph:

Anything that has a constructor or needs to run code to be initialized

5条回答
  •  暖寄归人
    2021-02-15 02:38

    If the static object is defined in an object that does not get referenced, the linker can prune the object completely, including the static initializer code. It will do so regularly for libs (that's how the libc does not get completely linked in when using parts of it under gnu, e.g.).

    Interestingly, I don't think this is specific to libraries. It can probably happen for objects even in the main build.

提交回复
热议问题