← Back to categorized notes
systems / old wiki reference

Static Initialization Order Fiasco

c++systemsruntime ~1 min

Objects with static storage duration in different translation units are initialized in an order that can surprise you.

If one global depends on another global from a different translation unit, construction can happen too early and crash before main ever starts.

The practical pattern is to move the dependency behind a function-local static: construct on first use, not at link-order roulette time.