mr4th-dynamic-linking/linux_before_main/linux_before_main.c

28 lines
377 B
C

// define the "before main" function
int x = 0;
__attribute__((constructor))
static void run_before_main_func(void){
x = 100;
}
// main
#include <stdio.h>
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