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

前端 未结 9 615
攒了一身酷
攒了一身酷 2020-12-01 11:30

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?

9条回答
  •  伪装坚强ぢ
    2020-12-01 12:09

    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.

提交回复
热议问题