Is there such a blog https://www.ibm.com/developerworks/community/blogs/12bb75c9-dfec-42f5-8b55-b669cc56ad76/entry/_e8_b7_a8c__e6_96_87_e4_bb_b6_e5_92_8c_e5_ba_93_e5_af_b9_e9_9d_99_e6_80_81_e5_af_b9_e8_b1_a1_e8_bf_9b_e8_a1_8c_e5_88_9d_e5_a7_8b_e5_8c_965 on IBM China Development blog? Lang = ZH
The compiler cannot guarantee the initialization sequence of non-local static object initialization order across multiple files or libraries. Therefore, the non-local static object initialization order is used to initialize other objects, this causes other objects to be initialized as junk data in the memory.
This issue is mentioned in Clause 4 "correctly initialized before the object is used" in <valid tive C ++>. The solution is to change the non-local static object to the local static object in the function, and the function returns the reference of this object to use this function for initialization of other objects. This can be done because local-static-object will perform initialization only when this definition is met for the first time and will not be executed in the future. The function ensures that the object used to initialize other objects has been initialized. In this way, we will not see the situations mentioned in the above blog.
Of course, the blog also mentions that you can use the compiler to specify a priority for each module to display the initialization sequence of the specified module (of course not the compilation sequence), but for large projects, after all, it is not an applicable method,ArticleIt's a bit suspected of promoting the xlc compiler...