Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
INLINE FUNCTION
NAME: VRAJ PATEL
BATCH: A
ENROLL NO : 150410107082
INTRODUCTION
• In C, we have used Macro function an optimized technique used by
compiler to reduce the execution time etc.
• Inline function is introduced which is an optimization technique used
by the compilers especially to reduce the execution time. We will
cover “what, why, when & how” of inline functions.
What is inline function :
The inline functions are a C++ enhancement feature to increase the
execution time of a program.
Functions can be instructed to compiler to make them inline so that
compiler can replace those function definition wherever those are
being called.
Compiler replaces the definition of inline functions at compile time
instead of referring function definition at runtime.
if function is big (in term of executable instruction etc) then, compiler
can ignore the “inline” request and treat the function as normal
function.
How to make function inline:
• To make any function as inline, start its definitions with the keyword
“inline”.
inline int add(int a, int b)
{
return (a + b);
};

Recommended for you

Managing I/O in c++
Managing I/O in c++Managing I/O in c++
Managing I/O in c++

Stream is a sequence of bytes that serves as an input or output source. The input stream provides data to a program while the output stream receives output. The get() and put() functions handle single character I/O. The >> operator is overloaded in istream while << is overloaded in ostream. The ios class contains functions like width(), precision(), and fill() for formatting output. Iomanip provides manipulators to format output in a chained manner.

c++oops
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++

Classes allow users to bundle data and functions together. A class defines data members and member functions. Data members store data within each object, while member functions implement behaviors. Classes support access specifiers like public and private to control access to members. Objects are instances of classes that allocate memory for data members. Member functions can access object data members and are called on objects using dot notation. Friend functions allow non-member functions to access private members of classes.

07. Virtual Functions
07. Virtual Functions07. Virtual Functions
07. Virtual Functions

This presentation describes runtime polymorphism (virtual functions) in C++, difference between method overloading & method overriding.

data structuresvirtual functionsmethod overriding
Why to use -
• In many places we create the functions for small work/functionality
which contain simple and less number of executable instruction.
Imagine their calling overhead each time they are being called by
callers.
•
When a normal function call instruction is encountered, the program
stores the memory address of the instructions immediately following
the function call statement, loads the function being called into the
memory, copies argument values, jumps to the memory location of
the called function, executes the function codes, stores the return
value of the function, and then jumps back to the address of the
instruction that was saved just before executing the called function.
Too much run time overhead.
• The C++ inline function provides an alternative.
• With inline keyword, the compiler replaces the function call
statement with the function code itself (process called expansion)
and then compiles the entire code.
• Thus, with inline functions, the compiler does not have to jump to
another location to execute the function, and then jump back as the
code of the called function is already available to the calling program.
Pros -
1. It speeds up your program by avoiding function calling overhead.
2. It save overhead of variables push/pop on the stack, when function calling
happens.
3. It save overhead of return call from a function.
4. It increases locality of reference by utilizing instruction cache.
5. By marking it as inline, you can put a function definition in a header file
(i.e. it can be included in multiple compilation unit, without the linker
complaining)
Cons -
1. It increases the executable size due to code expansion.
2. C++ inlining is resolved at compile time. Which means if you change the
code of the inline function, you would need to recompile all the code using it
to make sure it will be updated
3. When used in a header, it makes your header file larger with information
which users don’t care.
4. As mentioned above it increases the executable size, which may cause
thrashing in memory. More number of page fault bringing down your
program performance.
5. Sometimes not useful for example in embedded system where large
executable size is not preferred at all due to memory constraints.

Recommended for you

Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)

View study notes of Function overloading .you can also visit Tutorialfocus.net to get complete description step wise of the concerned topic.Other topics and notes of C++ are also explained.

function overloadingc++tutorialfocus.net
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++

Pointer is a variable that stores the memory address of another variable. It allows dynamic memory allocation and access of memory locations. There are three ways to pass arguments to functions in C++ - pass by value, pass by reference, and pass by pointer. Pass by value copies the value, pass by reference copies the address, and pass by pointer passes the address of the argument. Pointers can also point to arrays or strings to access elements. Arrays of pointers can store multiple strings. References are alternative names for existing variables and any changes made using the reference affect the original variable. Functions can return pointers or references.

computer scienceclass xii cbsepointers in c++
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++

The document discusses inheritance in C++. It defines inheritance as deriving a class from another class, allowing code reuse and fast development. There are different types of inheritance in C++: single inheritance where a class inherits from one base class; multiple inheritance where a class inherits from more than one base class; multilevel inheritance where a derived class inherits from another derived class; hierarchical inheritance where multiple subclasses inherit from a single base class; and hybrid inheritance which combines different inheritance types. Examples of each inheritance type are provided in C++ code snippets.

inheritance in c++single inheritancemultiple inheritance
When to use -
Function can be made as inline as per programmer need. Some useful
recommendation are mentioned below-
1. Use inline function when performance is needed.
2. Use inline function over macros.
3. Prefer to use inline keyword outside the class with the function
definition to hide implementation details.
Key Points -
1. It’s just a suggestion not compulsion. Compiler may or may not inline the
functions you marked as inline. It may also decide to inline functions not marked as
inline at compilation or linking time.
2. Inline works like a copy/paste controlled by the compiler, which is quite different
from a pre-processor macro: The macro will be forcibly inlined, will pollute all the
namespaces and code, won't be easy to debug.
3. All the member function declared and defined within class are Inline by default.
So no need to define explicitly.
4. Virtual methods are not supposed to be inlinable. Still, sometimes, when the
compiler can know for sure the type of the object (i.e. the object was declared and
constructed inside the same function body), even a virtual function will be inlined
because the compiler knows exactly the type of the object.
• 5. Template methods/functions are not always inlined (their presence
in an header will not make them automatically inline).
6. Most of the compiler would do in-lining for recursive functions but
some compiler provides #pragmas-
microsoft c++ compiler - inline_recursion(on) and once can also control
its limit with inline_depth.
In gcc, you can also pass this in from the command-line with --max-
inline-insns-recursive
Program code-
#include <iostream>
using namespace std;
inline int sqr(int x) output: ans is 9
{
int y;
y = x * x;
return y;
}
int main()
{
int a =3, b;
b = sqr(a);
cout <<"ans is "<<b;
return 0;
}

Recommended for you

FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT

This document discusses functions in C++. It defines what a function is and explains that functions are the building blocks of C++ programs. Functions allow code to be reused, making programs easier to code, modify and maintain. The document covers function definitions, declarations, calls, parameters, return types, scope, and overloading. It also discusses local and global variables as well as pass by value and pass by reference.

Command line arguments
Command line argumentsCommand line arguments
Command line arguments

Command-line arguments are given after the name of the program in command-line shell of Operating Systems. To pass command line arguments, we typically define main() with two arguments : first argument is the number of command line arguments and second is list of command-line arguments.

#commandlinearguments#argv#argc
Functions in c++
Functions in c++Functions in c++
Functions in c++

Functions allow programmers to structure C++ programs into modular segments of code to perform individual tasks. There are two types of functions: library functions and user-defined functions. User-defined functions are defined using a return type, function name, and parameters. Functions can be called by value or by reference and can also be inline, recursive, or friend functions.

THANK YOU

More Related Content

What's hot

Exception handling c++
Exception handling c++Exception handling c++
Exception handling c++
Jayant Dalvi
 
Object oriented programming c++
Object oriented programming c++Object oriented programming c++
Object oriented programming c++
Ankur Pandey
 
Encapsulation C++
Encapsulation C++Encapsulation C++
Encapsulation C++
Hashim Hashim
 
Managing I/O in c++
Managing I/O in c++Managing I/O in c++
Managing I/O in c++
Pranali Chaudhari
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
HalaiHansaika
 
07. Virtual Functions
07. Virtual Functions07. Virtual Functions
07. Virtual Functions
Haresh Jaiswal
 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)
Ritika Sharma
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
Vineeta Garg
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
Vishal Patil
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
03062679929
 
Command line arguments
Command line argumentsCommand line arguments
Command line arguments
Ashok Raj
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
Rokonuzzaman Rony
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
tanmaymodi4
 
Tokens in C++
Tokens in C++Tokens in C++
Tokens in C++
Mahender Boda
 
Functions in python
Functions in pythonFunctions in python
Functions in python
colorsof
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
rprajat007
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
Vineeta Garg
 
Function in c
Function in cFunction in c
Function in c
Raj Tandukar
 
Constructors and Destructor in C++
Constructors and Destructor in C++Constructors and Destructor in C++
Dynamic memory allocation in c++
Dynamic memory allocation in c++Dynamic memory allocation in c++
Dynamic memory allocation in c++
Tech_MX
 

What's hot (20)

Exception handling c++
Exception handling c++Exception handling c++
Exception handling c++
 
Object oriented programming c++
Object oriented programming c++Object oriented programming c++
Object oriented programming c++
 
Encapsulation C++
Encapsulation C++Encapsulation C++
Encapsulation C++
 
Managing I/O in c++
Managing I/O in c++Managing I/O in c++
Managing I/O in c++
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 
07. Virtual Functions
07. Virtual Functions07. Virtual Functions
07. Virtual Functions
 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Command line arguments
Command line argumentsCommand line arguments
Command line arguments
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
Tokens in C++
Tokens in C++Tokens in C++
Tokens in C++
 
Functions in python
Functions in pythonFunctions in python
Functions in python
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Function in c
Function in cFunction in c
Function in c
 
Constructors and Destructor in C++
Constructors and Destructor in C++Constructors and Destructor in C++
Constructors and Destructor in C++
 
Dynamic memory allocation in c++
Dynamic memory allocation in c++Dynamic memory allocation in c++
Dynamic memory allocation in c++
 

Similar to INLINE FUNCTION IN C++

inline function
inline functioninline function
inline function
SAURABH SHARMA
 
Inline functions
Inline functionsInline functions
Inline functions
DhwaniHingorani
 
Function Overloading,Inline Function and Recursion in C++ By Faisal Shahzad
Function Overloading,Inline Function and Recursion in C++ By Faisal ShahzadFunction Overloading,Inline Function and Recursion in C++ By Faisal Shahzad
Function Overloading,Inline Function and Recursion in C++ By Faisal Shahzad
Faisal Shehzad
 
Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptx
miki304759
 
OOP-Module-1-Section-4-LectureNo1-5.pptx
OOP-Module-1-Section-4-LectureNo1-5.pptxOOP-Module-1-Section-4-LectureNo1-5.pptx
OOP-Module-1-Section-4-LectureNo1-5.pptx
sarthakgithub
 
inline function
inline function inline function
inline function
imran khan
 
Chapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.pptChapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.ppt
AmanuelZewdie4
 
INLINE FUNCTIONS IOT68.pptx
INLINE FUNCTIONS IOT68.pptxINLINE FUNCTIONS IOT68.pptx
INLINE FUNCTIONS IOT68.pptx
ZalakPatel228771
 
5. Functions in C.pdf
5. Functions in C.pdf5. Functions in C.pdf
5. Functions in C.pdf
santosh147365
 
C++
C++C++
C++
dean129
 
Inline function(oops)
Inline function(oops)Inline function(oops)
Inline function(oops)
Jay Patel
 
C- language Lecture 4
C- language Lecture 4C- language Lecture 4
C- language Lecture 4
Hatem Abd El-Salam
 
C programming
C programmingC programming
C programming
Jigarthacker
 
Embedded _c_
Embedded  _c_Embedded  _c_
Embedded _c_
Moorthy Peesapati
 
Functions and modular programming.pptx
Functions and modular programming.pptxFunctions and modular programming.pptx
Functions and modular programming.pptx
zueZ3
 
Guidelines to understand durable functions with .net core, c# and stateful se...
Guidelines to understand durable functions with .net core, c# and stateful se...Guidelines to understand durable functions with .net core, c# and stateful se...
Guidelines to understand durable functions with .net core, c# and stateful se...
Concetto Labs
 
C question
C questionC question
C question
Kuntal Bhowmick
 
Presentation 2.pptx
Presentation 2.pptxPresentation 2.pptx
Presentation 2.pptx
ziyadaslanbey
 
Building blocks of Angular
Building blocks of AngularBuilding blocks of Angular
Building blocks of Angular
Knoldus Inc.
 
Functions in c++, presentation, short and sweet presentation, and details of ...
Functions in c++, presentation, short and sweet presentation, and details of ...Functions in c++, presentation, short and sweet presentation, and details of ...
Functions in c++, presentation, short and sweet presentation, and details of ...
Sar
 

Similar to INLINE FUNCTION IN C++ (20)

inline function
inline functioninline function
inline function
 
Inline functions
Inline functionsInline functions
Inline functions
 
Function Overloading,Inline Function and Recursion in C++ By Faisal Shahzad
Function Overloading,Inline Function and Recursion in C++ By Faisal ShahzadFunction Overloading,Inline Function and Recursion in C++ By Faisal Shahzad
Function Overloading,Inline Function and Recursion in C++ By Faisal Shahzad
 
Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptx
 
OOP-Module-1-Section-4-LectureNo1-5.pptx
OOP-Module-1-Section-4-LectureNo1-5.pptxOOP-Module-1-Section-4-LectureNo1-5.pptx
OOP-Module-1-Section-4-LectureNo1-5.pptx
 
inline function
inline function inline function
inline function
 
Chapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.pptChapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.ppt
 
INLINE FUNCTIONS IOT68.pptx
INLINE FUNCTIONS IOT68.pptxINLINE FUNCTIONS IOT68.pptx
INLINE FUNCTIONS IOT68.pptx
 
5. Functions in C.pdf
5. Functions in C.pdf5. Functions in C.pdf
5. Functions in C.pdf
 
C++
C++C++
C++
 
Inline function(oops)
Inline function(oops)Inline function(oops)
Inline function(oops)
 
C- language Lecture 4
C- language Lecture 4C- language Lecture 4
C- language Lecture 4
 
C programming
C programmingC programming
C programming
 
Embedded _c_
Embedded  _c_Embedded  _c_
Embedded _c_
 
Functions and modular programming.pptx
Functions and modular programming.pptxFunctions and modular programming.pptx
Functions and modular programming.pptx
 
Guidelines to understand durable functions with .net core, c# and stateful se...
Guidelines to understand durable functions with .net core, c# and stateful se...Guidelines to understand durable functions with .net core, c# and stateful se...
Guidelines to understand durable functions with .net core, c# and stateful se...
 
C question
C questionC question
C question
 
Presentation 2.pptx
Presentation 2.pptxPresentation 2.pptx
Presentation 2.pptx
 
Building blocks of Angular
Building blocks of AngularBuilding blocks of Angular
Building blocks of Angular
 
Functions in c++, presentation, short and sweet presentation, and details of ...
Functions in c++, presentation, short and sweet presentation, and details of ...Functions in c++, presentation, short and sweet presentation, and details of ...
Functions in c++, presentation, short and sweet presentation, and details of ...
 

Recently uploaded

system structure in operating systems.pdf
system structure in operating systems.pdfsystem structure in operating systems.pdf
system structure in operating systems.pdf
zyroxsunny
 
Response & Safe AI at Summer School of AI at IIITH
Response & Safe AI at Summer School of AI at IIITHResponse & Safe AI at Summer School of AI at IIITH
Response & Safe AI at Summer School of AI at IIITH
IIIT Hyderabad
 
Germany Offshore Wind 010724 RE (1) 2 test.pptx
Germany Offshore Wind 010724 RE (1) 2 test.pptxGermany Offshore Wind 010724 RE (1) 2 test.pptx
Germany Offshore Wind 010724 RE (1) 2 test.pptx
rebecca841358
 
Bangalore @ℂall @Girls ꧁❤ 0000000000 ❤꧂@ℂall @Girls Service Vip Top Model Safe
Bangalore @ℂall @Girls ꧁❤ 0000000000 ❤꧂@ℂall @Girls Service Vip Top Model SafeBangalore @ℂall @Girls ꧁❤ 0000000000 ❤꧂@ℂall @Girls Service Vip Top Model Safe
Bangalore @ℂall @Girls ꧁❤ 0000000000 ❤꧂@ℂall @Girls Service Vip Top Model Safe
bookhotbebes1
 
L-3536-Cost Benifit Analysis in ESIA.pptx
L-3536-Cost Benifit Analysis in ESIA.pptxL-3536-Cost Benifit Analysis in ESIA.pptx
L-3536-Cost Benifit Analysis in ESIA.pptx
naseki5964
 
Vernier Caliper and How to use Vernier Caliper.ppsx
Vernier Caliper and How to use Vernier Caliper.ppsxVernier Caliper and How to use Vernier Caliper.ppsx
Vernier Caliper and How to use Vernier Caliper.ppsx
Tool and Die Tech
 
一比一原版(skku毕业证)韩国成均馆大学毕业证如何办理
一比一原版(skku毕业证)韩国成均馆大学毕业证如何办理一比一原版(skku毕业证)韩国成均馆大学毕业证如何办理
一比一原版(skku毕业证)韩国成均馆大学毕业证如何办理
hahehot
 
MSBTE K Scheme MSBTE K Scheme MSBTE K Scheme MSBTE K Scheme
MSBTE K Scheme MSBTE K Scheme MSBTE K Scheme MSBTE K SchemeMSBTE K Scheme MSBTE K Scheme MSBTE K Scheme MSBTE K Scheme
MSBTE K Scheme MSBTE K Scheme MSBTE K Scheme MSBTE K Scheme
Anwar Patel
 
Profiling of Cafe Business in Talavera, Nueva Ecija: A Basis for Development ...
Profiling of Cafe Business in Talavera, Nueva Ecija: A Basis for Development ...Profiling of Cafe Business in Talavera, Nueva Ecija: A Basis for Development ...
Profiling of Cafe Business in Talavera, Nueva Ecija: A Basis for Development ...
IJAEMSJORNAL
 
GUIA_LEGAL_CHAPTER-9_COLOMBIAN ELECTRICITY (1).pdf
GUIA_LEGAL_CHAPTER-9_COLOMBIAN ELECTRICITY (1).pdfGUIA_LEGAL_CHAPTER-9_COLOMBIAN ELECTRICITY (1).pdf
GUIA_LEGAL_CHAPTER-9_COLOMBIAN ELECTRICITY (1).pdf
ProexportColombia1
 
Application Infrastructure and cloud computing.pdf
Application Infrastructure and cloud computing.pdfApplication Infrastructure and cloud computing.pdf
Application Infrastructure and cloud computing.pdf
Mithun Chakroborty
 
LeetCode Database problems solved using PySpark.pdf
LeetCode Database problems solved using PySpark.pdfLeetCode Database problems solved using PySpark.pdf
LeetCode Database problems solved using PySpark.pdf
pavanaroshni1977
 
Literature Reivew of Student Center Design
Literature Reivew of Student Center DesignLiterature Reivew of Student Center Design
Literature Reivew of Student Center Design
PriyankaKarn3
 
Unblocking The Main Thread - Solving ANRs and Frozen Frames
Unblocking The Main Thread - Solving ANRs and Frozen FramesUnblocking The Main Thread - Solving ANRs and Frozen Frames
Unblocking The Main Thread - Solving ANRs and Frozen Frames
Sinan KOZAK
 
IWISS Catalog 2024
IWISS Catalog 2024IWISS Catalog 2024
IWISS Catalog 2024
Iwiss Tools Co.,Ltd
 
How to Manage Internal Notes in Odoo 17 POS
How to Manage Internal Notes in Odoo 17 POSHow to Manage Internal Notes in Odoo 17 POS
How to Manage Internal Notes in Odoo 17 POS
Celine George
 
Development of Chatbot Using AI/ML Technologies
Development of  Chatbot Using AI/ML TechnologiesDevelopment of  Chatbot Using AI/ML Technologies
Development of Chatbot Using AI/ML Technologies
maisnampibarel
 
Evento anual Splunk .conf24 Highlights recap
Evento anual Splunk .conf24 Highlights recapEvento anual Splunk .conf24 Highlights recap
Evento anual Splunk .conf24 Highlights recap
Rafael Santos
 
CONVEGNO DA IRETI 18 giugno 2024 | PASQUALE Donato
CONVEGNO DA IRETI 18 giugno 2024 | PASQUALE DonatoCONVEGNO DA IRETI 18 giugno 2024 | PASQUALE Donato
CONVEGNO DA IRETI 18 giugno 2024 | PASQUALE Donato
Servizi a rete
 
Trends in Computer Aided Design and MFG.
Trends in Computer Aided Design and MFG.Trends in Computer Aided Design and MFG.
Trends in Computer Aided Design and MFG.
Tool and Die Tech
 

Recently uploaded (20)

system structure in operating systems.pdf
system structure in operating systems.pdfsystem structure in operating systems.pdf
system structure in operating systems.pdf
 
Response & Safe AI at Summer School of AI at IIITH
Response & Safe AI at Summer School of AI at IIITHResponse & Safe AI at Summer School of AI at IIITH
Response & Safe AI at Summer School of AI at IIITH
 
Germany Offshore Wind 010724 RE (1) 2 test.pptx
Germany Offshore Wind 010724 RE (1) 2 test.pptxGermany Offshore Wind 010724 RE (1) 2 test.pptx
Germany Offshore Wind 010724 RE (1) 2 test.pptx
 
Bangalore @ℂall @Girls ꧁❤ 0000000000 ❤꧂@ℂall @Girls Service Vip Top Model Safe
Bangalore @ℂall @Girls ꧁❤ 0000000000 ❤꧂@ℂall @Girls Service Vip Top Model SafeBangalore @ℂall @Girls ꧁❤ 0000000000 ❤꧂@ℂall @Girls Service Vip Top Model Safe
Bangalore @ℂall @Girls ꧁❤ 0000000000 ❤꧂@ℂall @Girls Service Vip Top Model Safe
 
L-3536-Cost Benifit Analysis in ESIA.pptx
L-3536-Cost Benifit Analysis in ESIA.pptxL-3536-Cost Benifit Analysis in ESIA.pptx
L-3536-Cost Benifit Analysis in ESIA.pptx
 
Vernier Caliper and How to use Vernier Caliper.ppsx
Vernier Caliper and How to use Vernier Caliper.ppsxVernier Caliper and How to use Vernier Caliper.ppsx
Vernier Caliper and How to use Vernier Caliper.ppsx
 
一比一原版(skku毕业证)韩国成均馆大学毕业证如何办理
一比一原版(skku毕业证)韩国成均馆大学毕业证如何办理一比一原版(skku毕业证)韩国成均馆大学毕业证如何办理
一比一原版(skku毕业证)韩国成均馆大学毕业证如何办理
 
MSBTE K Scheme MSBTE K Scheme MSBTE K Scheme MSBTE K Scheme
MSBTE K Scheme MSBTE K Scheme MSBTE K Scheme MSBTE K SchemeMSBTE K Scheme MSBTE K Scheme MSBTE K Scheme MSBTE K Scheme
MSBTE K Scheme MSBTE K Scheme MSBTE K Scheme MSBTE K Scheme
 
Profiling of Cafe Business in Talavera, Nueva Ecija: A Basis for Development ...
Profiling of Cafe Business in Talavera, Nueva Ecija: A Basis for Development ...Profiling of Cafe Business in Talavera, Nueva Ecija: A Basis for Development ...
Profiling of Cafe Business in Talavera, Nueva Ecija: A Basis for Development ...
 
GUIA_LEGAL_CHAPTER-9_COLOMBIAN ELECTRICITY (1).pdf
GUIA_LEGAL_CHAPTER-9_COLOMBIAN ELECTRICITY (1).pdfGUIA_LEGAL_CHAPTER-9_COLOMBIAN ELECTRICITY (1).pdf
GUIA_LEGAL_CHAPTER-9_COLOMBIAN ELECTRICITY (1).pdf
 
Application Infrastructure and cloud computing.pdf
Application Infrastructure and cloud computing.pdfApplication Infrastructure and cloud computing.pdf
Application Infrastructure and cloud computing.pdf
 
LeetCode Database problems solved using PySpark.pdf
LeetCode Database problems solved using PySpark.pdfLeetCode Database problems solved using PySpark.pdf
LeetCode Database problems solved using PySpark.pdf
 
Literature Reivew of Student Center Design
Literature Reivew of Student Center DesignLiterature Reivew of Student Center Design
Literature Reivew of Student Center Design
 
Unblocking The Main Thread - Solving ANRs and Frozen Frames
Unblocking The Main Thread - Solving ANRs and Frozen FramesUnblocking The Main Thread - Solving ANRs and Frozen Frames
Unblocking The Main Thread - Solving ANRs and Frozen Frames
 
IWISS Catalog 2024
IWISS Catalog 2024IWISS Catalog 2024
IWISS Catalog 2024
 
How to Manage Internal Notes in Odoo 17 POS
How to Manage Internal Notes in Odoo 17 POSHow to Manage Internal Notes in Odoo 17 POS
How to Manage Internal Notes in Odoo 17 POS
 
Development of Chatbot Using AI/ML Technologies
Development of  Chatbot Using AI/ML TechnologiesDevelopment of  Chatbot Using AI/ML Technologies
Development of Chatbot Using AI/ML Technologies
 
Evento anual Splunk .conf24 Highlights recap
Evento anual Splunk .conf24 Highlights recapEvento anual Splunk .conf24 Highlights recap
Evento anual Splunk .conf24 Highlights recap
 
CONVEGNO DA IRETI 18 giugno 2024 | PASQUALE Donato
CONVEGNO DA IRETI 18 giugno 2024 | PASQUALE DonatoCONVEGNO DA IRETI 18 giugno 2024 | PASQUALE Donato
CONVEGNO DA IRETI 18 giugno 2024 | PASQUALE Donato
 
Trends in Computer Aided Design and MFG.
Trends in Computer Aided Design and MFG.Trends in Computer Aided Design and MFG.
Trends in Computer Aided Design and MFG.
 

INLINE FUNCTION IN C++

  • 1. INLINE FUNCTION NAME: VRAJ PATEL BATCH: A ENROLL NO : 150410107082
  • 2. INTRODUCTION • In C, we have used Macro function an optimized technique used by compiler to reduce the execution time etc. • Inline function is introduced which is an optimization technique used by the compilers especially to reduce the execution time. We will cover “what, why, when & how” of inline functions.
  • 3. What is inline function : The inline functions are a C++ enhancement feature to increase the execution time of a program. Functions can be instructed to compiler to make them inline so that compiler can replace those function definition wherever those are being called. Compiler replaces the definition of inline functions at compile time instead of referring function definition at runtime. if function is big (in term of executable instruction etc) then, compiler can ignore the “inline” request and treat the function as normal function.
  • 4. How to make function inline: • To make any function as inline, start its definitions with the keyword “inline”. inline int add(int a, int b) { return (a + b); };
  • 5. Why to use - • In many places we create the functions for small work/functionality which contain simple and less number of executable instruction. Imagine their calling overhead each time they are being called by callers. • When a normal function call instruction is encountered, the program stores the memory address of the instructions immediately following the function call statement, loads the function being called into the memory, copies argument values, jumps to the memory location of the called function, executes the function codes, stores the return value of the function, and then jumps back to the address of the instruction that was saved just before executing the called function. Too much run time overhead.
  • 6. • The C++ inline function provides an alternative. • With inline keyword, the compiler replaces the function call statement with the function code itself (process called expansion) and then compiles the entire code. • Thus, with inline functions, the compiler does not have to jump to another location to execute the function, and then jump back as the code of the called function is already available to the calling program.
  • 7. Pros - 1. It speeds up your program by avoiding function calling overhead. 2. It save overhead of variables push/pop on the stack, when function calling happens. 3. It save overhead of return call from a function. 4. It increases locality of reference by utilizing instruction cache. 5. By marking it as inline, you can put a function definition in a header file (i.e. it can be included in multiple compilation unit, without the linker complaining)
  • 8. Cons - 1. It increases the executable size due to code expansion. 2. C++ inlining is resolved at compile time. Which means if you change the code of the inline function, you would need to recompile all the code using it to make sure it will be updated 3. When used in a header, it makes your header file larger with information which users don’t care. 4. As mentioned above it increases the executable size, which may cause thrashing in memory. More number of page fault bringing down your program performance. 5. Sometimes not useful for example in embedded system where large executable size is not preferred at all due to memory constraints.
  • 9. When to use - Function can be made as inline as per programmer need. Some useful recommendation are mentioned below- 1. Use inline function when performance is needed. 2. Use inline function over macros. 3. Prefer to use inline keyword outside the class with the function definition to hide implementation details.
  • 10. Key Points - 1. It’s just a suggestion not compulsion. Compiler may or may not inline the functions you marked as inline. It may also decide to inline functions not marked as inline at compilation or linking time. 2. Inline works like a copy/paste controlled by the compiler, which is quite different from a pre-processor macro: The macro will be forcibly inlined, will pollute all the namespaces and code, won't be easy to debug. 3. All the member function declared and defined within class are Inline by default. So no need to define explicitly. 4. Virtual methods are not supposed to be inlinable. Still, sometimes, when the compiler can know for sure the type of the object (i.e. the object was declared and constructed inside the same function body), even a virtual function will be inlined because the compiler knows exactly the type of the object.
  • 11. • 5. Template methods/functions are not always inlined (their presence in an header will not make them automatically inline). 6. Most of the compiler would do in-lining for recursive functions but some compiler provides #pragmas- microsoft c++ compiler - inline_recursion(on) and once can also control its limit with inline_depth. In gcc, you can also pass this in from the command-line with --max- inline-insns-recursive
  • 12. Program code- #include <iostream> using namespace std; inline int sqr(int x) output: ans is 9 { int y; y = x * x; return y; } int main() { int a =3, b; b = sqr(a); cout <<"ans is "<<b; return 0; }