While working on a library depending on another third party library, I ran into the problem that the third party library is absolutely trash requires a manual call to a global setup and cleanup function.
int main()
{
setup();
//do stuff
cleanup();
}
Now, this is a total sh*t show not much of a problem in application code since it is just syntactically horrifying, but is actually a pain in a library.
The library is supposed to abstract these weird implementation details away, and requiring the user to call a setup function is like slapping my own face.
I tried to make them disappear
//namespace scope
struct AutoMagic
{
AutoMagic() {setup();}
~AutoMagic() {cleanup();}
};
AutoMagic automagic;
And then I realized this won't work across translation units as seen here and there
- C++ global initialization order ignores dependencies?
- Is initialization order guaranteed
- C++ Dynamic initialization - across translation units
- Initialization across c++ translation units
- C++ static initialization order
Thus the question in the title.