liveBook · Manning

Static storage

As explained in Modern C

static is a C storage class specifier that gives an object static storage duration and can affect linkage.

An object with static storage duration exists for the entire program execution. It can be defined at file scope or declared inside a function block with the static storage-class specifier. Static duration does not make an identifier visible everywhere: scope still controls visibility. section 13.2.1 section 13.2

Static-duration objects are always initialized. Their initialization must be possible at compile time or through the system’s startup procedure; when no initializer is provided, the object is initialized to zero. section 13.2.1 section 13.4

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. (view table figure)
Class Scope Definition Linkage Duration Lifetime
Initialized File Yes External Static Whole execution
extern, initialized File Yes External Static Whole execution
Compound literal File Yes N/A Static Whole execution
String literal Any Yes N/A Static Whole execution
static, initialized 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
Compound literal     N/A    
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 with array Block Yes None Automatic To the end of expression

Compare storage classes by scope, linkage, storage duration, and initialization. section 13.2

How Modern C covers it

How deep it goes
Defines static duration, its declaration routes, whole-execution lifetime, and initialization constraints, while only briefly noting linker mechanics.
Examples
Uses file-scope objects, block-scope static variables, and a compound literal to illustrate static duration.
What you can do after
Understand which objects persist throughout execution and how static duration affects their initialization.
How it connects
Connects storage duration with scope, linkage, initialization, and object lifetime.

Also explained in

Compare how 2 books explain static storage →

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.