关于GCC的__attribute__ ((constructor))
来源:互联网 发布:pkpm软件分类 编辑:程序博客网 时间:2024/05/29 23:45
关于GCC的__attribute__ ((constructor))
gcc为函数提供了几种类型的属性,其中包含:构造函数(constructors)和析构函数(destructors)。
程序员应当使用类似下面的方式来指定这些属性:
带有"构造函数"属性的函数将在main()函数之前被执行,而声明为"析构函数"属性的函数则将在main()退出时执行。
下面给出一个简单的程序作为例子:
- /* test.c */
- #include<stdio.h>
- __attribute__((constructor)) void before_main()
- {
- printf("before main/n");
- }
- __attribute__((destructor)) void after_main()
- {
- printf("after main/n");
- }
- int main()
- {
- printf("in main/n");
- return 0;
- }
$ gcc test.c -o test
$ ./test
before main
in main
after main
根据上面的代码以及输出结果,我们可以猜到__attribute__((constructor))表示这段代码将在main函数前调用,就像在C++里面的全局变量类的构造一样.
- 关于GCC的__attribute__ ((constructor))
- 关于GCC的__attribute__ ((constructor))
- 关于GCC的__attribute__(constructor)
- 关于GCC的__attribute__ ((constructor))
- 关于GCC的__attribute__(constructor)
- GCC的__attribute__ ((constructor))和__attribute__ ((destructor))
- gcc的__attribute__ ((constructor))和__attribute__ ((destructor))
- GCC的__attribute__ ((constructor))和__attribute__ ((destructor))
- GCC __attribute__((constructor)|(destructor))
- Gcc扩展:__attribute__((constructor))
- GCC __attribute__((constructor)|(destructor))
- GCC __attribute__((constructor)|(destructor))
- GCC __attribute__((constructor)|(destructor))
- gcc下__attribute__ ((constructor))和__attribute__ ((destructor))的使用
- gcc下__attribute__ ((constructor))和__attribute__ ((destructor))的使用
- GCC中 __attribute__((constructor)|(destructor))
- gcc __attribute__关键字举例之constructor/destructor
- __attribute__((constructor)) 高版本gcc不执行
- 字符串转枚举
- 简单脉搏波波形分析系统设计与实现
- iOS7初体验(3)——图像资源Images Assets
- 安卓航班Android开发经典教程大总结1----基础编程及源码推送
- Javascript中最常用的55个经典技巧
- 关于GCC的__attribute__ ((constructor))
- C++笔记_类和对象_类的定义_访问限定和信息隐藏
- springSecurity源码分析——DelegatingFilterProxy类的作用
- Lua中table的ipairs和pairs以及function的:和.区别
- js刷新页面方法大全
- CentOS 6.3安装配置LAMP服务器(Apache+PHP5+MySQL)
- [jtable]用法(包括建立jtable和数据更新)
- boost 库在windows 系统下,gcc编译器编译
- tomcat映射路径的配置方法