Well, the main reason is efficiency. Every time a function is called, a series of instructions must be executed, both to set up the function call, including pushing any arguments onto the stack, and to return from the function. For inline functions this is not required.
As for the exectuable being larger, the general rule is:
1) if the inline function is small, the exe will be smaller.
2) if the inline function is large, the exe will be larger.
As for you using inline functions "in all your classes", you can but it's worth remembering "inline" is not a command to your compiler but a request, so it may not end up actually being inline, depending on the function.
The main reasons for a compiler not choosing to make a function inline are often:
1) the function contains a loop, switch or a goto.
2) it's recursive.
3) its contains static variables.
But why are static variables a problem to the compiler when compiling inline? I'd have thought they were probably the simplest sort of variables that it has to deal with?
I can see that recursion would obviously be impossible in line, because what inline code is really trying to do is insert a set of instructions as they appear into each function which "calls" the inline code, rather than write the code somewhere else and call it. Therefore any function that calls itself would just become an endless loop from the compiler's point of view: a function that it has to keep on starting from scratch again and again...
Inline functions take up more memory don't they? Since they paste the function wherever it is being called from. The benefit is the program does less jumping around to get the info. it needs. From what i've heard in large programs this speeds up the program.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.