Static Duration, Internal Linkage
Applying the static modifier to a file-scope variable gives it internal linkage. The difference between internal linkage and external linkage becomes meaningful in multifile programs. In that context, a variable with internal linkage is local to the file that contains it. But a regular external variable has external linkage, meaning that it can be used in different files, as the previous example showed.
What if you want to use the same name to denote different variables in different files? Can you just omit the extern?
// file1int errors = 20; // external declaration...---------------------------------------------// file2int errors = 5; // ??known to file2 only??void froobish(){ cout << errors; // ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access