Search code examples
cgccinline

Preventing gcc from inlining all functions


The following code prevents GCC compiler inline a specific function.

void __attribute__ ((noinline)) my_func() 
{
  ... 
}

I wish to prevent gcc from inlining all functions. Can I do it without adding the attribute to all functions?


Solution

  • The global option to avoid inlining (when using -O2 or other optimisation flags) is -fno-inline

    -fno-inline Do not expand any functions inline apart from those marked with the always_inline attribute. This is the default when not optimizing.

    (source: https://gcc.gnu.org/onlinedocs/gcc-4.9.1/gcc/Optimize-Options.html)

    If you're doing this to reduce code size, I suggest that you throw in the -Os option (optimize for size)