Linkage of Identifiers

An identifier that is declared more than once, whether in different scopes (in different files, for example) or in the same scope, may refer to the same variable or function. Identifiers must be “linked” in this way in order for a variable to be used “globally,” across different source files, for example.

Each identifier has either external, internal, or no linkage. These three kinds of linkage have the following significance:

External linkage

An identifier with external linkage represents the same object or function throughout the entire program, i. e., in all source files and libraries belonging to the program. The identifier is made known to the linker.

When a second declaration of the same identifier with external linkage occurs, the linker associates the identifier with the same object or function. A declaration of an existing external object is sometimes called a reference declaration .

Internal linkage

An identifier with internal linkage represents the same object or function within a given translation unit. The linker has no information about identifiers with internal linkage. Thus they remain “internal” to the translation unit.

No linkage

If an identifier has no linkage, then any further declaration using the identifier declares something new, such as a new variable or a new type.

The linkage of an identifier is determined by its storage class; that is, by the position of the declaration and any storage class specifier included in it. Only identifiers ...

Get C Pocket Reference 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.