From ISO Standard Draft: §3.0/9:
n3234 says:
A name used in more than one translation unit can potentially refer to the
same entity in these translationunits depending on the linkage (3.5) of the
name specified in each translation unit.
Can anyone explain this point with an example, please?
What is that statement actually saying? Can any one prove this point in terms of a program?
Sure! What this is saying is that if you have multiple source files (translation units) that both use some name (for example, the name of a variable, class or function), then it’s possible that those different files are talking about the same variable, class, or function, assuming that that entity was declared in a way that makes it visible across different files (that is, depending on its linkage).
For example, if I have this file:
A.cpp:
And this one here:
B.cpp:
Then in both files, the name
globalIntrefers to the globalintvariableglobalIntdefined in A.cpp. That’s all that this point is saying.Note, however, that if I declare
globalIntwithout external linkage, then the two files will be talking about different variables. For example, in this case:C.cpp:
D.cpp:
Now the
globalIntvariable referenced in C.cpp is not the same as the one in D.cpp, even though they have the same name.Hope this helps!