When to Use Inline Functions

I've just googled it and I find out when to use them, but I don't know what they mean:

• Function calls (including parameter passing and placing the object's address on the stack)
• Preservation of caller's stack frame //what does stack frame means
• New stack-frame setup
• Return-value communication
• Old stack-frame restore
• Return
------------------------------------------------------------------------------------------------
Quoted: http://msdn.microsoft.com/en-us/library/1w2887zk(v=vs.100).aspx
------------------------------------------------------------------------------------------------

And are there any other times to use inlined function?
Last edited on
i don't understand your bullet points, but these links seems to make sense to me:
http://stackoverflow.com/questions/1932311/when-to-use-inline-function-and-when-not-to-use-it
http://stackoverflow.com/questions/145838/benefits-of-inline-functions-in-c (see the comment that has 77 'points').
the bullet points are the arguments why inline is better than a #define macro

what does stack frame means
The stack is where the local variables reside.
The stack frame is basically how the stack is represented. Especially a pointer is maintained where the next local variable (and internal data like return address) is stored.
If that stack pointer is invalid your program will very likely crash
the bullet points are the arguments why inline is better than a #define macro

Ahhh makes more sense now ta.
the bullet points are the arguments why inline is better than a #define macro

No. Most of the bullet points itemize why an inline function is better than a function call that is not inlined. Each of the bullet points lists an overhead of an explicit function call.
- An inline function does not make an explicit function call, so the there is no overhead of pushing the stack frame nor of a jump instruction to the function.
- Preservation of caller's stack frame. This has no bearing on performance. The caller's stack frame remains intact whether the function is inlined or not. An linlined function "may" push additional variables on the stack.
- New stack frame setup - This doesn't happen with an inlined function.
- Return value - An inlined function "may" return a value. The value is left on the stack just the same as if returned from a non-inlined function.
- Old stack restore - If an inlined function has local storage, these values still have to be poped from the stack, although if the inlined function is small enough, these values will generally be in registers.
- Return. No need for an inlined function to return.

As previously pointed out, inline is merely a suggestion to the compiler and is up to the implementation as to how to implement. YMMV.

As for comparing inline to #define , IMO, with an optimizing compiler, there might not be any difference. Of course this depends on how well each is written.
lol makes even more sense to me now :)
nice example of where stackoverflow isn't always perfect:
wrong answer: 54 votes: http://stackoverflow.com/a/1932371/273767
right answer: 29 votes: http://stackoverflow.com/a/1932580/273767
Topic archived. No new replies allowed.