__attribute__((constructor)) 和 __attribute__((destructor))

__attribute__((constructor)) 先于main()函数调用
__attribute__((destructor))在main()函数后调用

#include <stdio.h>

#include <stdlib.h>

static void before(void) __attribute__((constructor));
static void after(void) __attribute__((destructor));

static void before() {
       printf("before main\n");
}


static void after(void) {
       printf("after main\n");
}

int main() {
       printf("main\n");
       return 0;
}

关于Zeno Chen

本人涉及的领域较多,杂而不精 程序设计语言: Perl, Java, PHP, Python; 数据库系统: MySQL,Oracle; 偶尔做做电路板的开发,主攻STM32单片机
此条目发表在C/C++分类目录。将固定链接加入收藏夹。