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);
};
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.
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;
}
THANK YOU

More Related Content

What's hot

Data types in c++
Data types in c++Data types in c++
Data types in c++
Venkata.Manish Reddy
 
C tokens
C tokensC tokens
C tokens
Manu1325
 
Operators in java
Operators in javaOperators in java
Operators in java
Then Murugeshwari
 
C++ OOPS Concept
C++ OOPS ConceptC++ OOPS Concept
C++ OOPS Concept
Boopathi K
 
Command line arguments
Command line argumentsCommand line arguments
Command line arguments
Ashok Raj
 
Inline functions
Inline functionsInline functions
Inline functions
DhwaniHingorani
 
Object oriented programming c++
Object oriented programming c++Object oriented programming c++
Object oriented programming c++
Ankur Pandey
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
rprajat007
 
Union in C programming
Union in C programmingUnion in C programming
Union in C programming
Kamal Acharya
 
Tokens in C++
Tokens in C++Tokens in C++
Tokens in C++
Mahender Boda
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
03062679929
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
tanmaymodi4
 
Function Pointer
Function PointerFunction Pointer
Function Pointer
Dr-Dipali Meher
 
This pointer
This pointerThis pointer
This pointer
Kamal Acharya
 
Union in c language
Union  in c languageUnion  in c language
Union in c language
tanmaymodi4
 
Constructors and Destructor in C++
Constructors and Destructor in C++Constructors and Destructor in C++
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
Dr Sukhpal Singh Gill
 

What's hot (20)

Data types in c++
Data types in c++Data types in c++
Data types in c++
 
C tokens
C tokensC tokens
C tokens
 
Operators in java
Operators in javaOperators in java
Operators in java
 
C++ OOPS Concept
C++ OOPS ConceptC++ OOPS Concept
C++ OOPS Concept
 
Function in C program
Function in C programFunction in C program
Function in C program
 
Command line arguments
Command line argumentsCommand line arguments
Command line arguments
 
Inline functions
Inline functionsInline functions
Inline functions
 
Object oriented programming c++
Object oriented programming c++Object oriented programming c++
Object oriented programming c++
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
Union in C programming
Union in C programmingUnion in C programming
Union in C programming
 
Tokens in C++
Tokens in C++Tokens in C++
Tokens in C++
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
Function Pointer
Function PointerFunction Pointer
Function Pointer
 
Vectors in Java
Vectors in JavaVectors in Java
Vectors in Java
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
This pointer
This pointerThis pointer
This pointer
 
Union in c language
Union  in c languageUnion  in c language
Union in c language
 
Constructors and Destructor in C++
Constructors and Destructor in C++Constructors and Destructor in C++
Constructors and Destructor in C++
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
 

Similar to INLINE FUNCTION IN C++

inline function
inline functioninline function
inline function
SAURABH SHARMA
 
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
 
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
 
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
 
CPP06 - Functions
CPP06 - FunctionsCPP06 - Functions
CPP06 - Functions
Michael Heron
 

Similar to INLINE FUNCTION IN C++ (20)

inline function
inline functioninline function
inline function
 
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 ...
 
CPP06 - Functions
CPP06 - FunctionsCPP06 - Functions
CPP06 - Functions
 

Recently uploaded

TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSETECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
DuvanRamosGarzon1
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
abh.arya
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
ankuprajapati0525
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdf
Kamal Acharya
 
Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
Kamal Acharya
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
Courier management system project report.pdf
Courier management system project report.pdfCourier management system project report.pdf
Courier management system project report.pdf
Kamal Acharya
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
seandesed
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 

Recently uploaded (20)

TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSETECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdf
 
Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
Courier management system project report.pdf
Courier management system project report.pdfCourier management system project report.pdf
Courier management system project report.pdf
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 

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