liveBook · Manning

Internal linkage

As explained in Modern C, Third Edition

Internal linkage is the property restricting an identifier's designated entity to a single translation unit.

Internal linkage restricts an identifier's designated entity to one translation unit. File-scope objects or functions that do not connect to other object files should use internal linkage, while identifiers shared across object files require external linkage. section 13.2

A file-local helper

static int square(int x) { return x * x; } int calculate(void) { return square(5); } The static declaration gives square internal linkage: code in another object file cannot use that identifier to refer to this function. The function remains available throughout the program's execution, so internal linkage is distinct from storage duration. section 13.2

Table 13.1 Storage classes, scope, linkage of identifiers, and storage duration of the associated objects. Tentative indicates that a definition is implied only if there is no other definition with an initializer. Induced indicates that the linkage is internal if another declaration with internal linkage has been met prior to that declaration; otherwise, it is external. Compound literals follow similar rules with respect to the block in which they occur, if any.
Class Scope Definition Linkage Duration Lifetime
Initialized File Yes External Static Whole execution
extern, initialized File Yes External Static Whole execution
String literal Any Yes N/A Static Whole execution
static, initialized Any Yes Internal Static Whole execution
constexpr Any Yes Internal Static Whole execution
Uninitialized File Tentative External Static Whole execution
extern, uninitialized Any No Induced Static Whole execution
static, uninitialized Any Tentative Internal Static Whole execution
thread_local File Yes External Thread Whole thread
extern thread_local Any No External Thread Whole thread
static thread_local Any Yes internal Thread Whole thread
Non-VLA None
Non-VLA, auto Block Yes None Automatic Block of definition
register None
VLA Block Yes None Automatic From definition to
end of block
Function return Block Yes None Automatic To the end of
with array expression

Compare storage classes, scope, linkage, definitions, initialization, and storage duration in one reference table. section 13.2

How Modern C, Third Edition covers it

How deep it goes
Distinguishes linkage from storage duration and relates static declarations to identifier scope and linker behavior.
Examples
Uses static file-scope functions and a comparison table covering declarations, scope, linkage, and duration.
What it assumes
Assumes familiarity with C declarations and object files while distinguishing linkage from storage duration.
What you can do after
Evaluate whether a C identifier should remain private to one translation unit or be shared through external linkage.
How it connects
Connects internal linkage with external linkage, storage duration, scope, storage classes, and the linker.

Also explained in

Compare how 2 books explain internal linkage →

Related concepts

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