2024-04-24 13:34:29 +00:00
|
|
|
// 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);
|
2024-04-24 19:04:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#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
|