Presentation is loading. Please wait.

Presentation is loading. Please wait.

Inline Function. 2 Expanded in a line when it is invoked Ie compiler replace the function call with function code To make a function inline the function.

Similar presentations


Presentation on theme: "Inline Function. 2 Expanded in a line when it is invoked Ie compiler replace the function call with function code To make a function inline the function."— Presentation transcript:

1 Inline Function

2 2 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; }

3 3 Inline Function 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

4 4 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

5 5 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

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


Download ppt "Inline Function. 2 Expanded in a line when it is invoked Ie compiler replace the function call with function code To make a function inline the function."

Similar presentations


Ads by Google