Inline Function
- Éloïse Hamadi
- 24 mars
- 1 min de lecture
Ilining a function(C++98) is an efficient way to speed up execution.
Rather than making a function call, the function's code is inserted directly at the point where it’s called.

Why ?
Because function calls take more time, and accessing memory is slower. By inlining we eliminate the overhead of the call itself.
Steps of a Non-Inline Function Call:
Function Call:
The CPU saves the return address (the location to continue after the function) and places it on the stack.
The CPU then calls the required function.
Passing Arguments:
Arguments are either loaded into registers or pushed onto the stack (depending on the compiler's decision).
Jump to Function:
The CPU jumps to the function's memory address to start executing the function and temporarily pauses the execution of the program.
Execute Function Body:
The CPU runs the code inside the function, for example, calculating x * x.
Return:
The CPU retrieves the return address from the stack and jumps back to the next instruction in the main program after the function call.
Retrieve Result:
The result is placed in a register or on the stack, ready for the next instruction (for example, result = 25)
Summary:
Keep return address → Load arguments in registers/stack → Jump to function’s address → Execute the function → Return result in register/stack.
Comments