liveBook · Manning

Linkage

As explained in Modern C

Linkage is a property of a C identifier that determines whether declarations in different scopes or translation units designate the same entity.

Consider two declarations named i: a local unsigned i initialized to 2, and a file-scope unsigned i initialized to 1. Inside the if block, extern unsigned i refers to the existing file-scope object, so the program prints 1; outside that declaration, the local name refers to the object initialized to 2. TAKEAWAY: linkage determines whether declarations designate the same entity. section 13.2

The essential distinctions are:

  • External linkage lets declarations in different object files designate the same object or function; the linker establishes that correspondence. section 13.2
  • Internal linkage keeps a file-scope object or function connected only within its translation unit. section 13.2
  • Identifiers without cross-scope or cross-file identity have no linkage. Linkage belongs to identifiers, not to the objects they represent. section 13.2
  • Do not equate static storage duration with the static storage-class specifier: static can enforce internal linkage, while duration describes an object's lifetime. section 13.2

How Modern C covers it

How deep it goes
Distinguishes external, internal, and absent linkage, while relating them to scope, storage duration, and storage classes.
Examples
Uses local-variable shadowing, an extern declaration, file-scope objects, and a storage-class comparison table.
What you can do after
Evaluate which declarations designate the same object or function and distinguish linkage from storage duration.
How it connects
Connects linkage with scope, storage duration, lifetime, storage classes, translation units, object files, and the linker.

Also explained in

Compare how 2 books explain linkage →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C. The section links point to the parts of the book it draws on.