您的位置:首页 > 其它

GCC __attribute__((constructor和(destructor)) (Cygwin)

2011-11-23 09:30 281 查看
关注点:__attribute__机制,用于声明,而不是定义,并且其位置约束为放于声明的尾部“;”之前。

 

对于__attribute__((constructor和(destructor)) ,

用法一:

void before_main() __attribute__((constructor));

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

void after_main() __attribute__((constructor));

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


亦可如此使用:

__attribute__((constructor)) void before_main()
{
printf("before main\n");
}

__attribute__((destructor)) void after_main()
{
printf("after main\n");
}


两种用法都可。

参考文章:http://blog.csdn.net/polisan/article/details/5031142
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  constructor destructor gcc