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.

Slides:



Advertisements
Similar presentations
Apr. 12, 2000Systems Architecture I1 Systems Architecture I (CS ) Lecture 6: Branching and Procedures in MIPS* Jeremy R. Johnson Wed. Apr. 12, 2000.
Advertisements

CS Data Structures Appendix 1 How to transfer a simple loop- expression to a recursive function (factorial calculation)
Chapter 6. 2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single Value Pass by Reference Variable Scope.
C# Programming: From Problem Analysis to Program Design1 2 Your First C# Program.
WEL COME PRAVEEN M JIGAJINNI PGT (Computer Science) MTech[IT],MPhil (Comp.Sci), MCA, MSc[IT], PGDCA, ADCA, Dc. Sc. & Engg.
1. 2 FUNCTION INLINE FUNCTION DIFFERENCE BETWEEN FUNCTION AND INLINE FUNCTION CONCLUSION 3.
Functions Modules in C++ are called functions and classes
Object Oriented Programming using VC++. Introduction Program – Set of instruction written in a high level language High level language used for writing.
Macro & Function. Function consumes more time When a function is called, the copy of the arguments are passed to the parameters in the function. After.
 2003 Prentice Hall, Inc. All rights reserved. 1 Functions and Recursion Outline Function Templates Recursion Example Using Recursion: The Fibonacci Series.
Beginning C++ Through Game Programming, Second Edition by Michael Dawson.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
C Functions Programmer-defined functions – Functions written by the programmer to define specific tasks. Functions are invoked by a function call. The.
A First Book of C++: From Here To There, Third Edition2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
C++ function call by value The call by value method of passing arguments to a function copies the actual value of an argument into the formal parameter.
CPS120 Introduction to Computer Science Iteration (Looping)
C Programming Lecture 8-2 : Function (advanced). Recursive Function (recursion) A function that calls itself (in its definition) Classic example : factorial.
1 Homework / Exam Finish up K&R Chapters 3 & 4 Starting K&R Chapter 5 Next Class HW4 due next class Go over HW3 solutions.
C++ Function 1. Function allow to structure programs in segment of code to perform individual tasks. In C++, a function is a group of statements that.
Object Oriented Programming Spring COMSATS Institute of Information Technology Functions OOP in C++ by Robert Lafore - Chapter#5 Kaleem Ullah
CPS120: Introduction to Computer Science Decision Making in Programs.
COP4020 Programming Languages Subroutines and Parameter Passing Prof. Xin Yuan.
Chapters 1-5 Review C++ Class. Chapter 1 – the big picture Objects Class Inheritance Reusability Polymorphism and Overloading.
Liang, Introduction to C++ Programming, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 6 Advanced Function Features.
Week 2-3 Control flow (review) Conditional statements If, else, else if, switch-case, break Loop constructs for, while, do-while, break, continue, label--go;
Templates Class Templates Used to specify generic class types where class members data types can be specified as parameters, e.g. here is a generic List.
FUNCTIONS IN C++. DEFINITION OF A FUNCTION A function is a group of statements that together perform a task. Every C++ program has at least one function,
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson Slides4-2.ppt Modification date: March 23, Procedures Essential ingredient of high level.
Chapter 9 Functions Dept of Computer Engineering Khon Kaen University.
© Copyright 2013 by Pearson Education, Inc. All Rights Reserved. 1 Chapter 6 Functions.
#include using namespace std; // Declare a function. void check(int, double, double); int main() { check(1, 2.3, 4.56); check(7, 8.9, 10.11); } void check(int.
CPS120 Introduction to Computer Science Iteration (Looping)
Functions Sujana Jyothi C++ Workshop Day 2. Functions 3 Parameter transmission modes pass by value (default) pass by reference (&) pass by const reference.
Compiler Directives. The C Preprocessor u The C preprocessor (cpp) changes your source code based on instructions, or preprocessor directives, embedded.
C++ Programming Lecture 13 Functions – Part V The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
Programming Fundamentals. Topics to be covered Today Recursion Inline Functions Scope and Storage Class A simple class Constructor Destructor.
1 Advanced Topics in Functions Lecture Unitary Scope Resolution Operator Unary scope resolution operator ( :: )  Access global variable if.
MIT-AITI: Functions Defining and Invoking Functions Functions as Data Function Scope: The call Object Function Arguments: The arguments objects Function.
Functions Mark Hennessy Dept. Computer Science NUI Maynooth C++ Workshop 18 th – 22 nd September 2006.
 2000 Prentice Hall, Inc. All rights reserved Introduction Divide and conquer –Construct a program from smaller pieces or components –Each piece.
Methods.
2Object-Oriented Program Development Using C++ 3 Function Declarations and Definitions Analogize functions to methods –Share same basic features –Unlike.
Functions Skill Area 314 Part B. Lecture Overview Functions Function Prototypes Function Definitions Local Variables Global Variables Default Parameters.
Functions Modules in C++ are called functions and classes. Main reason to use functions is : – get aid in conceptual organization.
 2000 Prentice Hall, Inc. All rights reserved Program Components in C++ Function definitions –Only written once –These statements are hidden from.
LECTURE 19 Subroutines and Parameter Passing. ABSTRACTION Recall: Abstraction is the process by which we can hide larger or more complex code fragments.
C++ Programming Lecture 13 Functions – Part V By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Chapter 6 Modularity Using Functions
C++ Features Function Overloading Default Functions arguments Thinking about objects – relationship to classes Types of member functions Constructor and.
Macro Processor Design Options Recursive Macro Expansion General-Purpose Macro Processors Macro Processing within Language Translators.
Introduction to Programming
Computer Architecture & Operations I
Programming with ANSI C ++
Friend Class Friend Class A friend class can access private and protected members of other class in which it is declared as friend. It is sometimes useful.
FUNCTIONS In C++.
Functions and an Introduction to Recursion
Classes & Objects.
Chapter 5 Functions.
Chapter 5 Conclusion CIS 61.
Stack Memory 2 (also called Call Stack)
Conditional Statements
Miscellaneous C++ Topics
BBIT 212/ CISY 111 Object Oriented Programming (OOP)
Looping III (do … while statement)
Functions and an Introduction to Recursion
Systems Architecture I
Predefined Functions Revisited
Corresponds with Chapter 5
Presentation transcript:

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 definition preceded with the key word inline Syntax Inline data type function name(parameter list) { function body; }

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 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 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 Inline Function inline int Max(int x, int y) { return (x > y)? (x) : (y); } void main( ) { cout << "Max (20,10): " << Max(20,10) << endl; }