__attribute__((constructor)) call order confusion

前端 未结 4 1030
伪装坚强ぢ
伪装坚强ぢ 2021-02-06 02:55

The answer here demonstrates that __attribute__((constructor)) is not called after static initialization, it is called in the declaration order.

Then, w

4条回答
  •  旧巷少年郎
    2021-02-06 03:35

    Can you implement a "construct on first use" pattern for this global?

    e.g.

    Magic& gMagic()
    {
        static Magic magic;
        return magic;
    }
    

    It will get built after all regular static ctors, but before any regular code needs it.

提交回复
热议问题