Datasheet
LINKAGE
An executable program is usually created by compiling several independent trans-
lation units, then linking the resulting object files with preexisting libraries. A term
translation unit refers to a source code file together with any included files, but with-
out the source lines omitted by conditional preprocessor directives. A problem aris-
es when the same identifier is declared in different scopes (for example, in different
files), or declared more than once in the same scope.
The linkage is a process that allows each instance of an identifier to be associated cor-
rectly with one particular object or function. All identifiers have one of two linkage attrib-
utes, closely related to their scope: external linkage or internal linkage. These attributes
are determined by the placement and format of your declarations, together with an
explicit (or implicit by default) use of the storage class specifier
static or extern.
Each instance of a particular identifier with external linkage represents the same
object or function throughout the entire set of files and libraries making up the pro-
gram. Each instance of a particular identifier with internal linkage represents the
same object or function within one file only.
Linkage Rules
Local names have internal linkage; the same identifier can be used in different files
to signify different objects. Global names have external linkage; identifier signifies
the same object throughout all program files.
If the same identifier appears with both internal and external linkage within the same
file, the identifier will have internal linkage.
Internal Linkage Rules
1. names having file scope, explicitly declared as static, have internal linkage
2. names having file scope, explicitly declared as const and not explicitly
declared as extern, have internal linkage
3. typedef names have internal linkage
4. enumeration constants have internal linkage
External Linkage Rules
1. names having file scope, that do not comply to any of previously stated
internal linkage rules, have external linkage
180
MIKROELEKTRONIKA - SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Language Reference
mikroC PRO for AVR
CHAPTER 5