Request for the detailed description of “Static Initialization Order Fiasco”

后端 未结 1 1204
栀梦
栀梦 2021-01-24 18:18

I read about the SIOF in the faq-lite and still I really don\'t understand why the issue happens. I have a static library(.a) and I use that library to use its static const data

相关标签:
1条回答
  • 2021-01-24 18:38

    The static initialization order fiasco is fairly straightforward: static objects in a single translation unit are initialized in the order in which they are declared, but there is no guarantee as to the order in which static objects in different translation units are initialized with respect to each other.

    So, in your specific example, foos in main.cpp may be initialized before foo::foofaa, which is declared in libsource.cpp.

    0 讨论(0)
提交回复
热议问题