今天看代码的时候发现在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
先占个坑,回头去研究一下
阅读(1638) | 评论(0) | 转发(0) |