Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?
like image 628
nitin_cherian Avatar asked Jun 24 '12 06:06

nitin_cherian


People also ask

What is code inlining?

Inlining is the process of replacing a subroutine or function call at the call site with the body of the subroutine or function being called. This eliminates call-linkage overhead and can expose significant optimization opportunities.

What is function inlining in C?

An inline function is one for which the compiler copies the code from the function definition directly into the code of the calling function rather than creating a separate set of instructions in memory. This eliminates call-linkage overhead and can expose significant optimization opportunities.

Is it possible for the C++ compiler to ignore inlining?

Remember, inlining is only a request to the compiler, not a command. Compiler can ignore the request for inlining. Compiler may not perform inlining in such circumstances like: If a function contains a loop.

What is the O flag in GCC?

It indicates the output file, i.e. what your object-file or executable should be. You can see this information by doing gcc --help or man gcc .


2 Answers

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.

like image 163
Sanish Gopalakrishnan Avatar answered Sep 30 '22 15:09

Sanish Gopalakrishnan


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.

like image 39
lenx.wei Avatar answered Sep 30 '22 15:09

lenx.wei