1

Possible Duplicate:
Is it possible to force a function not to be inlined?

I have this class method that doesn't actually get created due to optimization in Release mode on Visual C++( the function simply gets "embedded" in the caller function, without having a proper prolog and epilog ). How do I tell the compiler to create a standalone function?

Community
  • 1
  • 1
JosephH
  • 8,465
  • 4
  • 34
  • 62

2 Answers2

4

You can use a pragma in VC++

#pragma auto_inline(off)

void non_inlined_func() { /* ... */ }

#pragma auto_inline() // returns to previous state

See the documentation here.

Ed S.
  • 122,712
  • 22
  • 185
  • 265
3

That's called an inline function. If you're linking against that module, you can move the implementation to a cpp file, so it's not visible outside. That way, any modules trying to use it will have to call it.

You can also disable set the compiler flag "inline function expansion" to Only __inline (/Ob1) to prevent inlining in the current module, assuming you're not marking it as inline.

Or use:

#pragma auto_inline(off)
void foo()
{
}
#pragma auto_inline()

EDIT:

I listed my first variant first as that's the proper way to do it. You should let the optimizer do what it can to speed up your code. It shouldn't matter to you if it's inlined in your own module (or others, for that matter, since the assembled code is still visible in your binary), but if you really must do it, choose the first option.

Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625