Linkage

Every name has linkage , which determines how the compiler and linker can use the name. Linkage has two aspects: scope and language. Scope linkage dictates which scopes have access to an entity. Language linkage dictates an entity’s properties that depend on programming language.

Scope Linkage

Scope linkage can be one of the following:

Internal linkage

A name with internal linkage can be referred to from a different scope within the same source file. At namespace scope (that is, outside of functions and classes), static declarations have internal linkage, as do const declarations that are not also extern. Data members of anonymous unions have internal linkage. Names in an unnamed namespace have internal linkage.

External linkage

A name with external linkage can be referred to from a different scope, possibly in a different source file. Functions and objects declared with the extern specifier have external linkage, as do entities declared at namespace scope that do not have internal linkage.

No linkage

A name with no linkage can be referred to only from within the scope where it is declared. Local declarations that are not extern have no linkage.

Language Linkage

image with no caption

Every function, function type, and object has a language linkage, which is specified as a simple character string. By default, the linkage is "C++“. The only other standard language linkage is "C“. All other language linkages ...

Get C++ In a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.