Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I force gcc to inline a function?

Does __attribute__((always_inline)) force a function to be inlined by gcc?

like image 862
HaltingState Avatar asked Dec 05 '11 05:12

HaltingState


People also ask

Does GCC automatically inline functions?

GCC automatically inlines member functions defined within the class body of C++ programs even if they are not explicitly declared inline .

Can a function be forced as inline?

There's no guarantee that functions will be inlined. You can't force the compiler to inline a particular function, even with the __forceinline keyword. When compiling with /clr , the compiler won't inline a function if there are security attributes applied to the function. The inline keyword is available only in C++.

How do you inline a function?

To inline a function, place the keyword inline before the function name and define the function before any calls are made to the function. The compiler can ignore the inline qualifier in case defined function is more than a line.

Why would a compiler not inline?

What is the reason? Remember, inlining is only a request to the compiler, not a command. Compiler can ignore the request for inlining.


1 Answers

Yes.

  • From documentation v4.1.2
  • From documentation latest

always_inline

Generally, functions are not inlined unless optimization is specified. For functions declared inline, this attribute inlines the function even if no optimization level was specified.

like image 130
RCE Avatar answered Sep 19 '22 04:09

RCE