David
David

Reputation: 753

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?

Upvotes: 3

Views: 5609

Answers (1)

Jean-François Fabre
Jean-François Fabre

Reputation: 140178

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)

Upvotes: 12

Related Questions