Where are static variables stored in C and C++?

前端 未结 16 2425
自闭症患者
自闭症患者 2020-11-22 02:00

In what segment (.BSS, .DATA, other) of an executable file are static variables stored so that they don\'t have name collision? For example:


foo.c:                  


        
16条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 02:41

    The storage location of the data will be implementation dependent.

    However, the meaning of static is "internal linkage". Thus, the symbol is internal to the compilation unit (foo.c, bar.c) and cannot be referenced outside that compilation unit. So, there can be no name collisions.

提交回复
热议问题