Better_Software_Header_Mobile Better_Software_Header_Web

Find what you need - explore our website and developer resources

MSVC - Debugging the Static Initialization Order

Debugging static constructor crashes before main() in MSVC

bool has_cbool has_ctor = false;  
__try  
{  
    bool const is_nested = __scrt_acquire_startup_lock();  
  
    if (__scrt_current_native_startup_state == __scrt_native_startup_state::initializing)  
    {  
        __scrt_fastfail(FAST_FAIL_FATAL_APP_EXIT);  
    }  
    else if (__scrt_current_native_startup_state == __scrt_native_startup_state::uninitialized)  
    {  
        __scrt_current_native_startup_state = __scrt_native_startup_state::initializing;  
  
        if (_initterm_e(__xi_a, __xi_z) != 0)  
            return 255;  
  
        _initterm(__xc_a, __xc_z);  // <--- THIS LINE (256)!
  
        __scrt_current_native_startup_state = __scrt_native_startup_state::initialized;  
    }  
    else  
    {  
        has_cctor = true;  
    }  
  
    __scrt_release_startup_lock(is_nested);

About KDAB

1 Comment

18 - Dec - 2025

Ilya

Jonatan_Wallmander

Jonatan Wallmander

Senior Developer

Sign up for the KDAB Newsletter

Learn Modern C++

Learn more