// this specific section contains before-main function pointers // this pragma ensures the compilation unit will generate this section #pragma section(".CRT$XCU", read) // declare the "before main" function static void run_before_main_func(void); // set the before-main execution function pointer __declspec(allocate(".CRT$XCU")) __pragma(comment(linker, "/INCLUDE:run_before_main_ptr")) void (*run_before_main_ptr)(void) = run_before_main_func; // define the "before main" function int x = 0; static void run_before_main_func(void){ x = 100; } // main #include int main(){ printf("x = %d\n", x); return(0); }