2.8 Linkage

Data objects and functions can be implicitly or explicitly assigned linkage. There are three kinds of linkage:

When more than one declaration of the same object or function is made, linkage is made. The linked declarations can be in the same scope or in different scopes. Externally linked objects are available to any function in any compilation unit used to create the executable file. Internally linked objects are available only to the compilation unit in which the declarations appear.

The concept of linkage and the static and extern keywords are related, but not directly. Using the extern keyword in an object's declaration does not guarantee external linkage. The following rules determine the actual linkage of an object or function:

Identifiers other than data objects and functions have no linkage. An identifier declared as a function parameter also has no linkage.

The following examples show declarations with different linkages:

extern int x;          /*  External linkage                        */
static int y;          /*  Internal linkage                        */
register int z;        /*  Illegal storage-class declaration       */

main ()                /*  Functions default to external linkage   */
{
    int w;             /*  No linkage                              */
    extern int x;      /*  External linkage                        */
    extern int y;      /*  Internal linkage                        */
    static int a;      /*  No linkage                              */
}

void func1 (int arg1)  /*  arg1 has no linkage                     */
{ }

In DEC C, a message is issued if the same object is declared with both internal and external linkage.


Previous Page | Next Page | Table of Contents | Index