Order of initialization of globals across TU

suggest change

Inside one translation unit, namespace-scope variables with dynamic initialization are initialized in the order of their definitions. Across translation units, that order is unspecified.

A program with the following files

#include <iostream>

int dummyFoo = ((std::cout << "foo"), 0);
#include <iostream>

int dummyBar = ((std::cout << "bar"), 0);
int main() {}

might produce as output:

foobar

or

barfoo

Using a namespace-scope object that is dynamically initialized in another translation unit is the static initialization order fiasco: that object may not have been initialized yet.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents