8

I have studied that

The inline specifier is a hint to the compiler that it should attempt to generate code [...] inline rather than laying down the code for the function once and then calling through the usual function call mechanism.

Questions:

  1. If optimization is turned off for the GCC compiler, is the inline specifier ignored?
  2. When inline functions are called recursively, which compiler option determines the 'depth of inlining', until it follows the normal function call mechanism ?
  3. If the inline function is invoked inside a for loop, does the same 'depth of inlining' come into the picture ?
4

2 回答 2

7

如果 GCC 编译器的优化关闭,是否会忽略 inline 说明符?

是的,如果在 GCC 中关闭优化,则不会内联任何函数。相当于-fno-inline编译时使用flag。看到这个链接

-fno-inline

Don't pay attention to the inline keyword. Normally this option is used to keep the compiler from expanding any functions inline. Note that if you are not optimizing, no functions can be expanded inline.

当递归调用内联函数时,哪个编译器选项确定“内联深度”,直到它遵循正常的函数调用机制?

选项max-inline-recursive-depthmax-inline-recursive-depth-auto。默认深度为 8。

于 2012-06-24T06:51:07.767 回答
2

除了 -fno-inline,您还需要使用 -fno-default-inline 来禁用类中的内联函数。当您使用 gdb 单步执行这些内联函数时,这很有用。

于 2012-06-24T07:46:53.003 回答