Storage Duration and Linkage in C and C++
summary
Explains why names are resolved per translation unit and how the linker uses external linkage to merge definitions; shows that extern without an initializer is a non‑defining declaration while extern with an initializer allocates storage. Demonstrates that static sometimes changes linkage, sometimes storage duration, and that C++ static member functions remove the implicit this parameter rather than change storage. Gives concrete examples: file‑scope totals with static vs extern, const objects having internal linkage in C++ so header constants work, and inline rules for one‑definition behavior.
AI-written summary · about
chapters (14)
- 0:00Start
- 8:43Translation Units and Object Modules
- 14:17Scope Regions in C
- 20:14Storage Class Specifiers
- 26:40Object Declarations and Definitions
- 31:26Storage Duration
- 37:09Internal Linkage
- 40:47No Linkage
- 41:48A Conceptual Model
- 43:19Storage-Class Specifiers and Functions
- 47:58The Curious Behavior of extern
- 52:10Linkage for Const Objects
- 55:02Inline Functions
- 57:23Key Points
related talks
55mSafe Static Initialisation & Clean Up in Libraries
59mWhat Happens After The Compiler in C++ (How Linking Works)
49mC++: Objects, their lifetime and pointers
01h 21mAn (In-)Complete Guide to C++ Object Lifetimes
01h 26mC++ Under the Hood: (Internal Class Mechanisms)
01h 01mSurprises in Object Lifetime
58mAn (In-)Complete Guide to C++ Object Lifetimes
01h 11mDynamic Memory Allocation Challenges in C++ Safety Critical Systems
