The second example is valid because you can still access the global a
from outside that translation unit.
The a
in the anonymous namespace provides a definition for a variable that has internal linkage. The a
at global namespace scope is a definition for a variable with external linkage. You can declare a extern int a;
in a different translation unit and use it.