Linkage

Two lexically identical identifiers declared in different scopes can be made to refer to the same function or data object by a process called linkage. There are three kinds of linkage:

In the set of source files and library and object files that will constitute a program, every instance of an identifier with external linkage denotes the same single function or data object. If the declarations differ a warning or error message will be given. Within one source file, each instance of an identifier with internal linkage denotes the same function or object. Identifiers with no linkage denote unique entities.

For an identifier of a function or data object declared with file scope, if the lexically first declaration contains the keyword static, then the identifier has internal linkage. Otherwise, the identifier has external linkage.

An identifier for anything other than a function or data object has no linkage. An identifier declared as a function parameter has no linkage. Similarly, any data object declared within a block without the keyword extern can only have one declaration in the same scope, and it has no linkage.

If the declaration of a function or data object contains the keyword extern, the identifier has the same linkage as any previous declaration of the identifier with file scope. If there is no previous declaration with file scope, the identifier has external linkage.


© 1991-2008 Prem Sobel. All Rights Reserved.