-
Inline functions...
What are the advantages/disadvantages of using inline functions? I know what they are, but I don't know the benefits/costs of using them. I see them almost everywhere in code, but if they were entirely beneficial, they would be part of every function. So, what gives?
-
Inline functions should be written in header files. Usually every function is in its own "code region" and when the function is called its parameters are put into the stack and program's execution jumps to that address where the function begins. In inline function's case the code won't be generated to any certain location but to that point where the inline function is called. So if you call an inline function multiple times you have its code multiple times in your executable.
So inline functions are usually very short functions that are called often (maybe >100000 times / sec). The benefit is that the execution doesn't need to jump to other location, which can be a time-saving if executed 100000 times / sec. Disadvantage is the code bloat caused by many inline function calls in your code, especially when the inline function is long. So they can increase the size of your executable tremendously.