Alex Rivera | Logout

How can I tell gcc not to inline a function?

Asked 2009-09-24T20:39:34.040
179

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?

Edit
Report

1 Answer

21

A portable way to do this is to call the function through a pointer:

void (*foo_ptr)() = foo;
foo_ptr();

Though this produces different instructions to branch, which may not be your goal. Which brings up a good point: what is your goal here?

answered 2009-09-24T20:59:04.220

Your Answer