Reputation: 861
What is right to say about global variable:
If it is declared without static
keyword:
file scope
and external linkage
ORprogram scope
and is visible to all files in the programIf it is declared with static
keyword:
global scope
and internal linkage
ORfile scope
and internal linkage
And how is global namespace scope related to this?
This notions are really confusing altough i think I understand how it works, but at different places they call it in different ways so i don't know which is right.
Upvotes: 1
Views: 628
Reputation: 310990
The answers for the first question are both incorrect.
The variable will have extrenal linkage indeed but will be visible in other program units only if it is declared in it.
As for the second question then indeed the variable will have file scope and internal linkage.
Any variable declared outside some explicitly specified namespace is considered as declared in the global namespace. Variavles with external or internal linkage can be declared in any namespace including the global namespace.
We are speaking about variables that are declared outside any function.
Upvotes: 1