I saw this question answering some of this, but at least not clearly my question.
I suspect that I should probably not access any global variables that requires code to execute (e.g. std::string
), but how about POD variables?
std::string s = "hello";
const char* c = "world";
extern std::string s2; // (actually below in the same TU)
__attribute__((constructor)) void init()
{
// safe to assume that !strcmp(c, "world");
// not safe to assume s == "hello"?
// even less safe to assume s2 == "foo";
}
std::string s2 = "foo";