Difference between internal and no linkage

前端 未结 3 1768
眼角桃花
眼角桃花 2021-02-02 14:22

Please refer to the following code that is in the same translation unit:

static int global_var; // file scope in C and global namespace scope in C++
                     


        
3条回答
  •  长发绾君心
    2021-02-02 15:07

    Generally static variables have internal linkage. You can't access the static variable or function in another file(in multiple file compilation situations), because its scope limited within this file(Internal linkage). Normally auto and register variables have no linkage.


    As i said above auto and register variables have no linkage. You can't declare these variables in global scope. static variables has internal linkage, scope is based on declaration, but not possible to access in another file. extern variables has external linkage, its possible to access these variables in another file.

    For more reference Storage classes

提交回复
热议问题