哪些函数可以在main函数之前执行

68 阅读1分钟
  • __attribute((constructor))

__attribute((constructor))修饰的函数在main函数之前执行

 __attribute((constructor)) void func1() {
     printf("func1\n");
 }
  • 全局static变量的初始化
int func2() {
    printf("func2\n");
    return 0;
}

static int n = func2()