nitin_cherian
nitin_cherian

Reputation: 6685

Depth of inlining in GCC compiler

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 ?

Upvotes: 8

Views: 1644

Answers (2)

lenx.wei
lenx.wei

Reputation: 86

Besides -fno-inline, you also need to use -fno-default-inline to disable inline functions in classes. This is useful when you use gdb to step into those inline functions.

Upvotes: 2

Sanish
Sanish

Reputation: 1729

If optimization is turned off for the GCC compiler, is the inline specifier ignored?

Yes, if optimization is turned off in GCC, no functions would be inlined. It is equivalent to using -fno-inline flag during compilation. See this link

-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.

When inline functions are called recursively, which compiler option determines the 'depth of inlining', until it follows the normal function call mechanism ?

Options max-inline-recursive-depth and max-inline-recursive-depth-auto. Default depth is 8.

Upvotes: 7

Related Questions