// define the "before main" function int x = 0; __attribute__((constructor)) static void run_before_main_func(void){ x = 100; } // main #include int main(){ printf("x = %d\n", x); return(0); } #if 0 // wrapped in a macro: #define BEFORE_MAIN(n) \ __attribute__((constructor)) static void n(void) BEFORE_MAIN(before_main_rule){ // do work here } #endif