C++: When (and how) are C++ Global Static Constructors Called?

后端 未结 5 1050
借酒劲吻你
借酒劲吻你 2020-11-29 03:13

I\'m working on some C++ code and I\'ve run into a question which has been nagging me for a while... Assuming I\'m compiling with GCC on a Linux host for an ELF target, wher

5条回答
  •  时光取名叫无心
    2020-11-29 03:43

    This depends heavy on the compiler and runtime. It's not a good idea to make any assumptions on the time global objects are constructed.

    This is especially a problem if you have a static object which depends on another one being already constructed.

    This is called "static initialization order fiasco". Even if thats not the case in your code, the C++Lite FAQ articles on that topic are worth a read.

提交回复
热议问题