patterncppCritical
What is external linkage and internal linkage?
Viewed 0 times
externalandinternallinkagewhat
Problem
I want to understand the external linkage and internal linkage and their difference.
I also want to know the meaning of
I also want to know the meaning of
const variables internally link by default unless otherwise declared as extern.Solution
When you write an implementation file (
Internal linkage refers to everything only in scope of a translation unit.
External linkage refers to things that exist beyond a particular translation unit. In other words, accessible through the whole program, which is the combination of all translation units (or object files).
.cpp, .cxx, etc) your compiler generates a translation unit. This is the source file from your implementation plus all the headers you #included in it. Internal linkage refers to everything only in scope of a translation unit.
External linkage refers to things that exist beyond a particular translation unit. In other words, accessible through the whole program, which is the combination of all translation units (or object files).
Context
Stack Overflow Q#1358400, score: 414
Revisions (0)
No revisions yet.