do not click

Meeting C++ 2024   |  Online   |  Training   |  Books   |  Survey   |  Job fair   |  Advertising   |  Jobposting   |  Login

Meeting C++ 2024 - The Static Initialization Order Fiasco - How to Properly Initialize Global State

Conference | Live Schedule | Talks | Get your ticket | Set your timezone

Jonathan Müller

On Day 3 at in Track A (Saphir Room)

Global variables are initialized before main() runs, but the relative initialization order is not necessarily well-defined. As such, accessing global state while you initialize your global variables, might not work the way you expect.

A simple solution is to stop using global variables completely. However, it is not always an option, so in this talk we'll discuss some real solutions to the problem. We'll cover simple wrappers, lazy initializers and nifty counters. And of course, we'll also discuss the best solution of them all - moving initialization to compile time with the help of constexpr and C++20's constinit keywords.

Please login to comment

Comment from Marc Mutz at 2020-12-01 17:01:40

Thanks for the talk, Jonathan. I think it's a must-watch for every C++-programmer. Static destruction order fiasco OMG!

Copyright Meetingcpp GmbH Imprint Piwik Opt out Privacy Policy