Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1071072
  • 博文数量: 132
  • 博客积分: 612
  • 博客等级: 中士
  • 技术积分: 1389
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-14 16:06
文章分类

全部博文(132)

文章存档

2015年(2)

2014年(55)

2013年(53)

2012年(2)

2011年(20)

分类: C/C++

2013-11-06 15:02:02

今天看代码的时候发现在main()执行前打印出来了一堆东西,找了半天没有找到,后来grep了一下找到了一个函数,它的后面有这个玩意 __attribute__ ((constructor)),由于google了一下,找到了答案:
Declaring Attributes of Functions
 
In GNU C, you declare certain things about functions called in your program which help
the compiler optimize function calls and check your code more carefully.
The keyword __attribute__ allows you to specify special attributes when making
a declaration. This keyword is followed by an attribute specification inside double
parentheses. The following attributes are currently defined for functions on all targets:
noreturn, returns_twice, noinline, always_inline, flatten, pure, const, nothrow,
sentinel, format, format_arg, no_instrument_function, section, constructor,
destructor, used, unused, deprecated, weak, malloc, alias, warn_unused_result,
nonnull and externally_visible. Several other attributes are defined for functions
on particular target systems. Other attributes, including section are supported for
variables declarations and for types
 
You may also specify attributes with ‘__’ preceding and following each keyword. This
allows you to use them in header files without being concerned about a possible macro of
the same name. For example, you may use __noreturn__ instead of noreturn.

使用 __attribute__ 加上 contructor 可以在main执行被执行,使用 destructor 可以在main退出后被执行;

参考链接为:http://filwmm1314.blog.163.com/blog/static/218259192012121225132/
http://www.cnblogs.com/respawn/archive/2012/07/09/2582078.html


先占个坑,回头去研究一下
阅读(1599) | 评论(0) | 转发(0) |
0

上一篇:tar.xz解压方法

下一篇:米3屏幕校准

给主人留下些什么吧!~~