I realise that the order of initialization of global static objects across multiple translation units is undefined; however, if a function is defined in the same translation unit as a global static, is the global guaranteed to have been initialized by the time the function is called? For example: is the following code safe?
foo.hpp:
[code=cpp]
struct foo { /* ... */ };
extern foo f;
extern foo b;
foo& bar();
[/code]
foo.cpp:
[code=cpp]
#include "foo.hpp"
foo f = bar();
[/code]
bar.cpp:
[code=cpp]
#include "foo.hpp"
foo b;
foo& bar() { return b; }
[/code]
foo.hpp:
[code=cpp]
struct foo { /* ... */ };
extern foo f;
extern foo b;
foo& bar();
[/code]
foo.cpp:
[code=cpp]
#include "foo.hpp"
foo f = bar();
[/code]
bar.cpp:
[code=cpp]
#include "foo.hpp"
foo b;
foo& bar() { return b; }
[/code]
Comment