当前位置: 技术问答>linux和unix
C99的inline的问题
来源: 互联网 发布时间:2016-04-14
本文导语: C99的inline的问题 请问gcc中的函数声明为inline的时候,为什么有时候并没有内嵌进去,我已经加了-finline-functions inline有什么条件吗? | http://blog.csdn.net/dengyunze/archive/2004/10/17/139471.aspx 好奇的问一句:为什...
C99的inline的问题
请问gcc中的函数声明为inline的时候,为什么有时候并没有内嵌进去,我已经加了-finline-functions
inline有什么条件吗?
请问gcc中的函数声明为inline的时候,为什么有时候并没有内嵌进去,我已经加了-finline-functions
inline有什么条件吗?
|
http://blog.csdn.net/dengyunze/archive/2004/10/17/139471.aspx
好奇的问一句:为什么一定要把大函数内联呢?
man gcc:
-finline-limit=n
By default, gcc limits the size of functions that can be inlined.
This flag allows the control of this limit for functions that are
explicitly marked as inline (ie marked with the inline keyword or
defined within the class definition in c++). n is the size of
functions that can be inlined in number of pseudo instructions (not
counting parameter handling). The default value of n is 600.
Increasing this value can result in more inlined code at the cost
of compilation time and memory consumption. Decreasing usually
makes the compilation faster and less code will be inlined (which
presumably means slower programs). This option is particularly
useful for programs that use inlining heavily such as those based
on recursive templates with C++.
Note: pseudo instruction represents, in this particular context, an
abstract measurement of functionâs size. In no way, it represents
a count of assembly instructions and as such its exact meaning
might change from one release to an another.
好奇的问一句:为什么一定要把大函数内联呢?
man gcc:
-finline-limit=n
By default, gcc limits the size of functions that can be inlined.
This flag allows the control of this limit for functions that are
explicitly marked as inline (ie marked with the inline keyword or
defined within the class definition in c++). n is the size of
functions that can be inlined in number of pseudo instructions (not
counting parameter handling). The default value of n is 600.
Increasing this value can result in more inlined code at the cost
of compilation time and memory consumption. Decreasing usually
makes the compilation faster and less code will be inlined (which
presumably means slower programs). This option is particularly
useful for programs that use inlining heavily such as those based
on recursive templates with C++.
Note: pseudo instruction represents, in this particular context, an
abstract measurement of functionâs size. In no way, it represents
a count of assembly instructions and as such its exact meaning
might change from one release to an another.
|
一个函数是否内嵌,是由编译器决定的。如果函数声明为inline,而编译器认为这个函数太大,那么编译器就会自作主张,不内嵌。
C++ Primer:
但是注意inline 指示对编译器来说只是一个建议编译器可以选择忽略该建议因为
把一个函数声明为inline 函数并不见得真的适合在调用点上展开例如一个递归函数
如rgcd()并不能在调用点完全展开虽然它的第一个调用可以一个1200 行的函数也不太
可能在调用点展开一般地inline 机制用来优化小的只有几行的经常被调用的函数
man gcc:
-finline-functions
Integrate all simple functions into their callers. The compiler
heuristically decides which functions are simple enough to be worth
integrating in this way.
C++ Primer:
但是注意inline 指示对编译器来说只是一个建议编译器可以选择忽略该建议因为
把一个函数声明为inline 函数并不见得真的适合在调用点上展开例如一个递归函数
如rgcd()并不能在调用点完全展开虽然它的第一个调用可以一个1200 行的函数也不太
可能在调用点展开一般地inline 机制用来优化小的只有几行的经常被调用的函数
man gcc:
-finline-functions
Integrate all simple functions into their callers. The compiler
heuristically decides which functions are simple enough to be worth
integrating in this way.
|
加上优化选项 -O
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。