Do objects of built-in types have special static initialisation order precedence?

前端 未结 4 542
梦如初夏
梦如初夏 2021-01-18 10:42

I\'d have expected the following code to yield a segmentation fault (or otherwise UB):

struct T {
   T();
};

T t;
char const* str = \"Test string\";

T::T()         


        
4条回答
  •  深忆病人
    2021-01-18 11:16

    char const* str = "Test string";
    

    is done by the compiler/linker, so it exists in its "initialized state" before the program even starts to run.

提交回复
热议问题