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

后端 未结 5 1053
借酒劲吻你
借酒劲吻你 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:45

    According to the C++ standard they are called before any function or object of their translation unit is used. Note that for objects in the global namespace this would mean they are initialized before main() is called. (See ltcmelo's and Martin's answers for mote details and a discussion of this.)

提交回复
热议问题