반응형

what code is it?


#define FORCENOINLINE __attribute__((noinline)) /* Force code to NOT be inline */



In brief, this code not use inline in c++ code and UE4 use it as FORCENOINLINE  macro,



FORCENOINLINE construct()  , you know what it means?, that's right





How can I tell gcc not to inline a function?



Say I have this small function in a source file

static void foo() {}

and I build an optimized version of my binary yet I don't want this function inlined (for optimization purposes). is there a macro I can add in a source code to prevent the inlining?

shareimprove this question
   
Thanks for this question! I was profiling with oprofile when a function did not show up, the answers here fixed this. – Simon A. Eugster Oct 29 '11 at 9:17

You want the gcc-specific noinline attribute.

This function attribute prevents a function from being considered for inlining. If the function does not have side-effects, there are optimizations other than inlining that causes function calls to be optimized away, although the function call is live. To keep such calls from being optimized away, put asm ("");

Use it like this:

void __attribute__ ((noinline)) foo() 
{
  ...
}
shareimprove this answer
25 
Using gcc 4.4.3 on Arch Linux, I get a syntax error with the attribute placed as above. It works correctly when it precedes the function (e.g., attribute ((noinline)) void foo() {}) – mrkj Apr 16 '10 at 14:24
2 
Arduino also wanted it placed before the function. – Peter N Lewis Feb 24 '12 at 9:49
2 
Edited to fix the attribute syntax. – Quuxplusone Jun 21 '13 at 20:59
   
The asm("") construct is actually fairly cross-platform and got the job done. I did it for x86 Linux and it did not cause a build problem on PowerPC AIX. Thanks for this useful suggestion! – Marty Nov 6 '14 at 23:58
   
Using gcc 6.2.1 on Arch Linux, no problem. – ManuelSchneid3r Oct 1 '16 at 14:46 






반응형

+ Recent posts