What happens to static variables when libraries are statically linked

后端 未结 3 1973
你的背包
你的背包 2021-02-09 12:21

Let\'s say I have library (A) implementing the singleton pattern (it has a static variable in its implementation).

(A) library is compiled as a

3条回答
  •  我在风中等你
    2021-02-09 12:57

    static linked library, and static variables are not related.

    A static variable, is not visible outside the current compilation scope (no symbol name is created in the .o file, so no other .o files can find that variable via the symbol name).

    This means that the variable

    static int foo; can exist in every compilation scope, and each one will be uniqe

提交回复
热议问题