//这种函数在main()之前执行。
#include <stdio.h>
/*
* This attribute lead gcc/ld to exec this function
* before the "main".
*/
__attribute__ ((__constructor__))
void pre_func(void) {
printf("pre_func\n");
}
同理在main函数退出只有执行的函数
static void stop(void) attribute ((destructor));
只需要有attribute ((constructor)) 关键字修饰即可