Where do static local variables go

后端 未结 3 1522
后悔当初
后悔当初 2021-02-08 06:05

Where are static local variables stored in memory? Local variables can be accessed only inside the function in which they are declared.

Global static variables go into t

3条回答
  •  暖寄归人
    2021-02-08 06:48

    Static variables go into the same segment as global variables. The only thing that's different between the two is that the compiler "hides" all static variables from the linker: only the names of extern (global) variables get exposed. That is how compilers allow static variables with the same name to exist in different translation units. Names of static variables remain known during the compilation phase, but then their data is placed into the .data segment anonymously.

提交回复
热议问题