Question

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 ?
Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top