I have a C++ program with three source files:
// main.cpp
auto return_value = managed_call(int value);
// managed.cpp
#include "private_impl.hpp"
int managed_call(int arg) {
if (arg == 0)
return private_func();
else
return arg;
}
//private_impl.cpp
static some_type some_var = construct_static_object_might_blow();
int private_func() {
....
return 42;
}
My question is about the initialization of the static object in private_impl.cpp
: "when does that take place?" or more specifically - is it only initialized if the private_func
function is called?
Update
I actually simplified the example a bit too much; the code in question will be run as a Python extension - i.e. it is dlopen()
which is the crucial init step. This SO question turned out to be spot on.