__attribute__用法
attribute((constructor))在main函数之前,执行一个函数,便于我们做一些准备工作
__attribute((constructor))void before()
{
printf(“before main\n”);
}
attribute((destructor))在main()函数退出或者调用了exit()之后调用
__attribute((destructor))void after()
{
printf(“before main\n”);
}
多个函数时,GCC为我们提供了一个参数叫优先级,构造按从小到大,析构函数相反
void __attribute__((constructor(5)) init_function1(void);
void __attribute__((constructor(10)) init_function1(void);