C++ has to run code before main if a ctor is in a class that's static. There's no other way to initialize that static object.
C prevents this by requiring static storage to be initialized with constants.
namespace { int myfunc() { return 5; } int x; int y = 4; int z = myfunc(); }; int main() {}