What is the difference between internal and external linkage (the static and extern keywords)?
Last updated
External linkage makes a name visible program-wide via the linker (default for non-const globals and free functions).
externdeclares it without defining it.Internal linkage keeps a name private to its translation unit: namespace-scope
static, unnamed namespaces, andconst/constexprglobals by default. This prevents link-time clashes.Prefer unnamed namespaces over file-scope
static, and C++17inlinevariables for shared globals defined in headers.