Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to force a function not to be inlined?

Tags:

c++

visual-c++

I want to force a little function not to be compiled as inline function even if it's very simple. I think this is useful for debug purpose. Is there any keyword to do this?

like image 889
Thomson Avatar asked Jul 25 '10 12:07

Thomson


People also ask

What functions Cannot be inlined?

The only situation in which a function cannot be inlined is if there is no definition for the function in the compilation unit. Even that will not prevent link-time inlining by a link-time optimizer.

How do you check if a function is inlined or not?

If you need to make sure that function is inlined and OK to go with proprietary extension in MS VC++, check out the __forceinline declarator. The compiler will either inline the function or, if it falls into the list of documented special cases, you will get a warning - so you will know the inlining status.

Can a function be forced as inline?

There's no guarantee that functions will be inlined. You can't force the compiler to inline a particular function, even with the __forceinline keyword. When compiling with /clr , the compiler won't inline a function if there are security attributes applied to the function. The inline keyword is available only in C++.


1 Answers

In Visual Studio 2010, __declspec(noinline) tells the compiler to never inline a particular member function, for instance:

class X {      __declspec(noinline) int member_func() {           return 0;       } }; 

edit: Additionally, when compiling with /clr, functions with security attributes never get inlined (again, this is specific to VS 2010).

I don't think it will prove at all useful at debugging, though.

like image 145
Michael Foukarakis Avatar answered Oct 02 '22 16:10

Michael Foukarakis