Inline Function Inline Function Expanded in a line

  • Slides: 6
Download presentation
Inline Function

Inline Function

Inline Function Expanded in a line when it is invoked Ie compiler replace the

Inline Function Expanded in a line when it is invoked Ie compiler replace the function call with function code To make a function inline the function definition preceded with the key word inline Syntax Inline data type function name(parameter list) { function body; } 2

Inline Function overheads When a function is called every time it takes a lot

Inline Function overheads When a function is called every time it takes a lot of extra time in executing series of instructions for tasks such as Jumping to the function definition Saving register Pushing arguments into stack and Return to the calling program To eliminate the function overheads C++ support a special function called inline function 3

Inline Function The keyword inline used to sends a request to the compiler not

Inline Function The keyword inline used to sends a request to the compiler not a command Compiler may ignore the request if the function definition is too large or too complicated and compile the function as normal function 4

Inline Function It is a function defined with a keyword ‘inline’ It does not

Inline Function It is a function defined with a keyword ‘inline’ It does not require function calling overhead. It also save overhead of variables push/pop on the stack, while function calling. Compiler replaces the function call with function definition It can not be recursive It can not contain any types of loops It can not have switch cases or nested if’s It can not have static variable or goto statements 5

Inline Function inline int Max(int x, int y) { return (x > y)? (x)

Inline Function inline int Max(int x, int y) { return (x > y)? (x) : (y); } void main( ) { cout << "Max (20, 10): " << Max(20, 10) << endl; } 6