Hacker News new | ask | show | jobs
by matzf 1238 days ago
Don't try this with C++, unless you're certain that there are no interdependencies or side-effects in global variable initialisation. The link order (usually) affects the order in which initialisers are executed.
2 comments

On the contrary: do do this and if you observe your program crashing due to linking order, fix the damn bug.
Developer PoV vs User/Distro PoV here :P you're not wrong, though...
Fair enough :) I just meant to point out what could go wrong.
Does the C++ spec guarantee initialization order? Or is any application that depends on it relying on undefined behaviour?
There's no mandated order between compilation units. It's a problem significant enough to have its own snarky name: the Static Initialization Order Fiasco https://en.cppreference.com/w/cpp/language/siof