What does "internal linkage" mean?
c++, linkage
Solution
A translation unit usually consists of single source file with all `#include`d files and results in one object file.
A name in namespace scope has by default external linkage, meaning you can refer that name from other translation units (with scope resolution operator or using directive). But if the name is qualified with `static`, the linkage becomes internal, and the name can not be referred outside the translation unit in which it was defined.
In your example you could access `a` if the namespace `A`, the name `a` and `main` method is in the same translation unit. But in `main`, you are declaring another variable `a`, which hides the `a` in namespace `A`. and the `a` in main is not initialized, so when you print, it actually prints garbage value from `a` declared in `main`. If you want to use `a` from `A` in `main`, use like `cout<<A::a` or use `using namespace A;` in the source file containing `main`.
Problem
In the standard it says that: When a name has internal linkage , the entity it denotes can be referred to by names from other scopes in the same translation unit. and: A name having namespace scope (3.3.6) has internal linkage if it is the name of — a variable, function or function template that is explicitly declared static; So consider the following code: ``` #include <stdio.h> namespace A { /* a with internal linkage now. Entity denoted by a will be referenced from another scope. This will be main() function scope in my case */ static int a=5; } int main() { int a; //declaring a for unqualified name lookup rules printf("%d\n",a);//-1216872448 } ``` I really don't understand the definitions in the standard. What does it mean that: the entity it denotes can be referred to by names from other scopes in the same translation unit.