C++ - static meaning for variables in global scope -


what significance of defining variable static when define in global scope? aren't global variables "static" anyway?

i.e: there difference between code? :

int var1 = 0; int main() {     return var1; }  static int var1 = 0; int main() {     return var1; } 

i know static variable not accessible other translation unit, that's not i'm concerned with.

aren't global variables "static" anyway?

global variables indeed placed in static memory. however, global in translation units, linker sees names.

is there difference between code? [...]

if decide link first code translation unit has var1, going link error. second code compile correctly, if var1 in other translation unit global.

i know static variable not accessible other translation unit, that's not i'm concerned with.

internal or external scope difference. 1 argue misuse of keyword static, way in c standard.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -