liveBook · Manning

Static storage

As explained in Modern C, Third Edition

A static object is a C object with static storage duration whose lifetime extends across the entire program execution.

An object with static storage duration lives for the entire program execution, including before application code begins. Its identifier’s visibility can be narrower than its lifetime. section 13.2.1 section 13.2

C objects can have static storage duration in several ways:

  • File-scope objects that are not declared thread_local, and block-scope variables or compound literals declared static. section 13.2.1
  • String literals, which always have static storage duration. section 13.2.1

Static-duration objects are always initialized. Initializers must be known at compile time or resolvable during process startup; objects without explicit initializers receive default initialization, such as zero for arithmetic types. section 13.2.1 section 13.4

 double A = 37; 1 
 double* p = &(static double){ 1.0, }; 
 int main(void) {
   static double B;
 }

The example combines a file-scope object, a pointer initialized with a static compound literal, and a block-scope static object. section 13.2.1

How Modern C, Third Edition covers it

How deep it goes
Defines lifetime, eligible object forms, and initialization constraints, including startup-resolved addresses.
Examples
Shows a file-scope object, a static compound literal, and a block-scope static object.
What you can do after
Understand which C objects persist throughout execution and how they are initialized.
How it connects
Connects object lifetime with scope, linkage, and initialization.

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, Third Edition. The section links point to the parts of the book it draws on.