How to know an inline function is really inline

This topic is 3858 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Is there a simply method? (without knowledge of dasm)

Share on other sites
You can't 'truly' know unless you look at the generated assembly and see how it is called and appears in the target. If you need help figuring it out though in ASM, you could use something like:

__asm { __emit 0x90 __emit 0x90 __emit 0x90 __emit 0x90 __emit 0x90 }// function body goes here__asm { __emit 0x90 __emit 0x90 __emit 0x90 __emit 0x90 __emit 0x90 }

What that does is pad 5 NOPs around the body of the code (but will still come after prolog and end before epilog code, reference) but you can open up a free disassembler, OlylDbg for example, and use the search command for 5 NOPS in a row and see where your code is. **

The only caveat to that is the compiler might optimize out certain things like that, but I am not sure. When going between debug and release configurations the code is different anyways so no telling if this is actually will work.

** The above is not truly tested against identifying inline code and is just an idea.

Share on other sites
just run your code with a profiler. inlined functions just don't show up there anymore.

Share on other sites
You could try putting a breakpoint on the line calling your function. When you run the app, you arrive at the breakpoint and tracing into the function does not actually get you into the code of that function it most probably is inlined.

But the best way is by looking at the generated code. It really isnt hard you know. Just put a breakpoint, run, right-click, get "show disassembly" and look if you see a "call ...." towards your function. If there is one, the function isnt inlined.

(all of the above was written with Visual C++ in mind as IDE ;) )

Share on other sites
Quote:
 Original post by KeisniIs there a simply method? (without knowledge of dasm)

Without looking at the assembly, I don't think you can. C++ doesn't have any way to guarantee that a function is inlined. The compiler can ignore the inline keyword if it wants to.

Share on other sites
Some compilers also provide the "__forceinline" keyword (MSVC does) but, once again, I'm not sure if it's 100% garanteed to come out inlined.

Share on other sites
Quote:
 Original post by TrillianSome compilers also provide the "__forceinline" keyword (MSVC does) but, once again, I'm not sure if it's 100% garanteed to come out inlined.

It isn't, in MSVC's case. It should however output a 4714 warning at compile time when failed.

Share on other sites
TBH it's barely worth inlining anything at all. Any language directive is only a hint and without it the compiler will still do what it thinks is best.

Share on other sites
Quote:
 Original post by DaveTBH it's barely worth inlining anything at all. Any language directive is only a hint and without it the compiler will still do what it thinks is best.

Some compilers, like Visual C++, can sometimes inline functions that are not declared as inline through whole program optimization and link time code generation. In general though if you have a function that is a good candidate for inlining (generally a short and simple function that you know is called with high frequency in performance sensitive code) then it is worth declaring it as inline and defining it in a header where it is visible to all callers as the optimizer is more likely to be able to inline it where appropriate.

• 10
• 16
• 9
• 13
• 41