SlideShare ist ein Scribd-Unternehmen logo
1 von 25
   Inline function.
   Workings of Inline
   Why need of Inline.
   Implementation in C++ with code example.
   Advantage against Macros.
   Where can be implemented.
   What is the use of function
    It is used to reduce the save the memory space when a
    function is likely to be called many times.
 Every  time a function is called, it take a lot
  of extra time in executing a series of
  instructions.
 In the following ways of execution it takes
  more time
 1. Jumping to the function
 2.Saving in Register.
 3.Pushing arguments into the stack.
 4.Returning to the calling function.
   Inline functions can be implemented using the keyword inline.
   The inline is a request to the compiler.
   The function always can not be inline by the compiler
   The complicated functions will not be inline.
   Just like a macro, but different from macro.
 C++   proposes a new feature called inline
  functions.
 By using this we can eliminate the cost of
  calls to small functions.
 An inline function is a function that in
  expanded in line when it is invoked.
 Inline function must be defined before they
  are called.
 Inline keyword sends a request, not a
  command to the compiler.
Inline function-header

{
      function body
}
   The inline function is just a code replacement instead of the
    function call.
   There is a need of stack storage and other special mechanism for
    function call and return.
   The stack storage is used to store the return value and return
    address for function call and return process.
   And while passing the parameter the stack storage needed to
    store the parameter values, and from the stack area the values
    moved to data area.
   While using the inline function, there is no need of these
    operations, because of code replacement.
   The compiler can do inline on either a high-level intermediate
    representation or a low-level intermediate representation.
   In either case, the compiler simply computes the arguments,
    stores them in variables corresponding to the function's
    arguments, and then inserts the body of the function at the call
    site.
 In an application, if the time complexity is to be reduced
  means the inline function can be used.
 The overhead of calling and returning from the function,
  parameter manipulation (push/ pop) are reduced.
 Increases locality of references by utilizing instruction
  cache.
 After inline the compiler may perform the optimization of
  the code by boycott the dead codes. i.e., the unused code
  lines that will always get true or false or not performing
  any modification in execution.
Example:
 int pred(int x) { if (x == 0) return 0; else return x - 1; }
Before inline
 int f(int y) { return pred(y) + pred(0) + pred(y+1); }
After inline
  int f(int y)
{
  int temp = 0;
  if (y == 0) temp += 0; else temp += y - 1;                     /*1*/
  if (0 == 0) temp += 0; else temp += 0 - 1;                     /*2*/
  if (y+1 == 0) temp += 0; else temp += (y + 1) - 1;             /*3*/
  return temp;
}
   The temp += 0 statements in the lines marked (1), (2) and (3)
    do nothing. The compiler can remove them.
   The condition 0 == 0 is always true, so the compiler can
    replace the line marked (2) with the consequent, temp += 0
    (which does nothing).
   The compiler can rewrite the condition y+1 == 0 to y == -1.
   The compiler can reduce the expression (y + 1) - 1 to y
    (assuming wraparound overflow semantics)
   The expressions y and y+1 cannot both equal zero. This lets the
    compiler eliminate one test.
   These are all the actions the compiler may do for the better
    resulting of the inline function implementation
   In C++ the function can be inline using the keyword ‘inline’.
   The member function of a class and the global functions are
    also possible to declare as inline.
   The compiler may or may not make the function as an inline
    we requested. It is up to the compiler.
   The advanced provisions made in Visual C++ to make a
    function as inline. The pragmas implemented.
   The recursive functions also may be implemented as inline in
    VC++.
#include<iostream.h>          int main()
#include<conio.h>             {
class samp                       samp k;
{                                clrscr();
   int h;                        k.display();
   public:                       cout<<"hi friends...n";
         samp(){h=0;};           k.display();
         void display();         getch();
};                               return 0;
inline void samp::display()
{                             }
   cout<<h<<endl;
}
#include<iostream.h>          return 0;
#include<conio.h>         }
void display()
{                         output :
   cout<<"nnin Inline   in Inline function
   functionn";
}
int main()
{
   clrscr();
display();
   getch();
   Macro invocations do not perform type checking, or even
    check that arguments are well-formed, whereas function calls
    usually do.
   Macro can not return any value where the function return.
   Some constructs may be difficult through macro, but can be
    done using inline function.
   Error correction in function is somewhat easier than Macro.
   Many compilers can also inline expand some recursive
    functions; recursive macros are typically illegal.
 Many  compilers can also inline expand some
  recursive functions; recursive macros are
  typically illegal.
 Major drawback is macros are not Functions
 Usual error checking does not occur during
  compilation.
Some constructs may be difficult through macro,
 but can be done using inline function.
inline double cube(double a)
{
        return(a*a*a);
}

The above function invoked by statements like
                                       OUTPUT:
1.cube(3.0);                           27
2.cube(2.5+1.5);                       64
d
   = cube(2.5+1.5);
{
      return(d*d*d);
}
Output: 64
This result will differ in macro definitions.
So, by this way also inline function is useful.
   The inline function must be simple and small.
   If the code size is too large, some compiler will not treat that as
    inline function.
   The inline expansion can not be recognized by the
    programmer. If the function is not treated as inline, then it will
    take care of compiler as normal function.
 In  the following situation inline expansion
  may not work:
1.For function returning values, if a loop, a
  switch or goto exists.
2.For function not returning values, if a
  return statement exists.
3.If function contains static variables.
4.If inline function are recursive.
   Wherever the execution time is need to reduce, there the inline
    function can be implemented. But the one thing is the memory
    consumption for storing the file may be increased.
   For example, assume while writing Operating system the
    inline function may be used to reduce the execution time. The
    simple and small code can be inline.
   And in mobile application, the memory available is more than
    enough. But application response time is a criteria means we
    can use inline function.
   Whenever the memory consumption is a constraint then
    inline will not be applied there as a solution., because
    inline will paste the code then and there, where the
    function call.
   For some embedded applications, the execution time can
    be extended, but memory is restricted.
   If the function is larger size, the speed benefits of inline
    function will reduce.
   Sometimes the overhead of the function call becomes
    small compared to execution of the function.
   On that time the benefits of inline function may be lost
The inline function is a special concept., which is
normally implemented in all C++ compilers and versions. But
based on the compiler version and vendor the inline
consideration and conformation differs. Some compilers may
accept the function declared as inline to do inline expansion.
Some compiler won’t.
Inline function

Weitere ähnliche Inhalte

Was ist angesagt?

Templates in C++
Templates in C++Templates in C++
Templates in C++
Tech_MX
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
Tech_MX
 
class and objects
class and objectsclass and objects
class and objects
Payel Guria
 

Was ist angesagt? (20)

Virtual function in C++ Pure Virtual Function
Virtual function in C++ Pure Virtual Function Virtual function in C++ Pure Virtual Function
Virtual function in C++ Pure Virtual Function
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Function overloading
Function overloadingFunction overloading
Function overloading
 
array of object pointer in c++
array of object pointer in c++array of object pointer in c++
array of object pointer in c++
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Interface
InterfaceInterface
Interface
 
Friend function in c++
Friend function in c++ Friend function in c++
Friend function in c++
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
C functions
C functionsC functions
C functions
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Constructor and destructor
Constructor  and  destructor Constructor  and  destructor
Constructor and destructor
 
class and objects
class and objectsclass and objects
class and objects
 

Andere mochten auch

Andere mochten auch (20)

Inline Functions and Default arguments
Inline Functions and Default argumentsInline Functions and Default arguments
Inline Functions and Default arguments
 
Inline function in C++
Inline function in C++Inline function in C++
Inline function in C++
 
Inline function in C++
Inline function in C++Inline function in C++
Inline function in C++
 
Inline functions & macros
Inline functions & macrosInline functions & macros
Inline functions & macros
 
inline function
inline function inline function
inline function
 
C++ Function
C++ FunctionC++ Function
C++ Function
 
functions of C++
functions of C++functions of C++
functions of C++
 
Friend functions
Friend functions Friend functions
Friend functions
 
Friend function & friend class
Friend function & friend classFriend function & friend class
Friend function & friend class
 
C++ programming function
C++ programming functionC++ programming function
C++ programming function
 
polymorphism
polymorphism polymorphism
polymorphism
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Friends function and_classes
Friends function and_classesFriends function and_classes
Friends function and_classes
 
Functions
FunctionsFunctions
Functions
 
Varnish caching technique
Varnish caching techniqueVarnish caching technique
Varnish caching technique
 
Cache memory
Cache memoryCache memory
Cache memory
 
Inline assembly language programs in c
Inline assembly language programs in cInline assembly language programs in c
Inline assembly language programs in c
 
14.jun.2012
14.jun.201214.jun.2012
14.jun.2012
 
Trends and technologies in system softwares
Trends and technologies in system softwaresTrends and technologies in system softwares
Trends and technologies in system softwares
 
Constants
ConstantsConstants
Constants
 

Ähnlich wie Inline function

Chapter 11 Function
Chapter 11 FunctionChapter 11 Function
Chapter 11 Function
Deepak Singh
 

Ähnlich wie Inline function (20)

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
 
Chap 5 c++
Chap 5 c++Chap 5 c++
Chap 5 c++
 
Chap 5 c++
Chap 5 c++Chap 5 c++
Chap 5 c++
 
Compiler optimizations based on call-graph flattening
Compiler optimizations based on call-graph flatteningCompiler optimizations based on call-graph flattening
Compiler optimizations based on call-graph flattening
 
inline function
inline functioninline function
inline function
 
Function in C++, Methods in C++ coding programming
Function in C++, Methods in C++ coding programmingFunction in C++, Methods in C++ coding programming
Function in C++, Methods in C++ coding programming
 
Presentation 2.pptx
Presentation 2.pptxPresentation 2.pptx
Presentation 2.pptx
 
[ITP - Lecture 12] Functions in C/C++
[ITP - Lecture 12] Functions in C/C++[ITP - Lecture 12] Functions in C/C++
[ITP - Lecture 12] Functions in C/C++
 
Presentation 2 (1).pdf
Presentation 2 (1).pdfPresentation 2 (1).pdf
Presentation 2 (1).pdf
 
Functions in c language
Functions in c languageFunctions in c language
Functions in c language
 
C++
C++C++
C++
 
(3) cpp procedural programming
(3) cpp procedural programming(3) cpp procedural programming
(3) cpp procedural programming
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
Object oriented programming system with C++
Object oriented programming system with C++Object oriented programming system with C++
Object oriented programming system with C++
 
cbybalaguruswami-e-180803051831.pptx
cbybalaguruswami-e-180803051831.pptxcbybalaguruswami-e-180803051831.pptx
cbybalaguruswami-e-180803051831.pptx
 
cbybalaguruswami-e-180803051831.pptx
cbybalaguruswami-e-180803051831.pptxcbybalaguruswami-e-180803051831.pptx
cbybalaguruswami-e-180803051831.pptx
 
Chapter 11 Function
Chapter 11 FunctionChapter 11 Function
Chapter 11 Function
 
Javascripts hidden treasures BY - https://geekyants.com/
Javascripts hidden treasures            BY  -  https://geekyants.com/Javascripts hidden treasures            BY  -  https://geekyants.com/
Javascripts hidden treasures BY - https://geekyants.com/
 
C++
C++C++
C++
 
Unit-III.pptx
Unit-III.pptxUnit-III.pptx
Unit-III.pptx
 

Mehr von Tech_MX

Virtual base class
Virtual base classVirtual base class
Virtual base class
Tech_MX
 
Theory of estimation
Theory of estimationTheory of estimation
Theory of estimation
Tech_MX
 
String & its application
String & its applicationString & its application
String & its application
Tech_MX
 
Statistical quality__control_2
Statistical  quality__control_2Statistical  quality__control_2
Statistical quality__control_2
Tech_MX
 
Stack data structure
Stack data structureStack data structure
Stack data structure
Tech_MX
 
Stack Data Structure & It's Application
Stack Data Structure & It's Application Stack Data Structure & It's Application
Stack Data Structure & It's Application
Tech_MX
 
Spanning trees & applications
Spanning trees & applicationsSpanning trees & applications
Spanning trees & applications
Tech_MX
 
Set data structure 2
Set data structure 2Set data structure 2
Set data structure 2
Tech_MX
 
Set data structure
Set data structure Set data structure
Set data structure
Tech_MX
 
Real time Operating System
Real time Operating SystemReal time Operating System
Real time Operating System
Tech_MX
 
Mouse interrupts (Assembly Language & C)
Mouse interrupts (Assembly Language & C)Mouse interrupts (Assembly Language & C)
Mouse interrupts (Assembly Language & C)
Tech_MX
 
Motherboard of a pc
Motherboard of a pcMotherboard of a pc
Motherboard of a pc
Tech_MX
 
More on Lex
More on LexMore on Lex
More on Lex
Tech_MX
 
MultiMedia dbms
MultiMedia dbmsMultiMedia dbms
MultiMedia dbms
Tech_MX
 
Merging files (Data Structure)
Merging files (Data Structure)Merging files (Data Structure)
Merging files (Data Structure)
Tech_MX
 
Memory dbms
Memory dbmsMemory dbms
Memory dbms
Tech_MX
 

Mehr von Tech_MX (20)

Virtual base class
Virtual base classVirtual base class
Virtual base class
 
Uid
UidUid
Uid
 
Theory of estimation
Theory of estimationTheory of estimation
Theory of estimation
 
String & its application
String & its applicationString & its application
String & its application
 
Statistical quality__control_2
Statistical  quality__control_2Statistical  quality__control_2
Statistical quality__control_2
 
Stack data structure
Stack data structureStack data structure
Stack data structure
 
Stack Data Structure & It's Application
Stack Data Structure & It's Application Stack Data Structure & It's Application
Stack Data Structure & It's Application
 
Spss
SpssSpss
Spss
 
Spanning trees & applications
Spanning trees & applicationsSpanning trees & applications
Spanning trees & applications
 
Set data structure 2
Set data structure 2Set data structure 2
Set data structure 2
 
Set data structure
Set data structure Set data structure
Set data structure
 
Real time Operating System
Real time Operating SystemReal time Operating System
Real time Operating System
 
Parsing
ParsingParsing
Parsing
 
Mouse interrupts (Assembly Language & C)
Mouse interrupts (Assembly Language & C)Mouse interrupts (Assembly Language & C)
Mouse interrupts (Assembly Language & C)
 
Motherboard of a pc
Motherboard of a pcMotherboard of a pc
Motherboard of a pc
 
More on Lex
More on LexMore on Lex
More on Lex
 
MultiMedia dbms
MultiMedia dbmsMultiMedia dbms
MultiMedia dbms
 
Merging files (Data Structure)
Merging files (Data Structure)Merging files (Data Structure)
Merging files (Data Structure)
 
Memory dbms
Memory dbmsMemory dbms
Memory dbms
 
Linkers
LinkersLinkers
Linkers
 

Kürzlich hochgeladen

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Kürzlich hochgeladen (20)

Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 

Inline function

  • 1.
  • 2. Inline function.  Workings of Inline  Why need of Inline.  Implementation in C++ with code example.  Advantage against Macros.  Where can be implemented.
  • 3. What is the use of function It is used to reduce the save the memory space when a function is likely to be called many times.
  • 4.  Every time a function is called, it take a lot of extra time in executing a series of instructions.  In the following ways of execution it takes more time  1. Jumping to the function  2.Saving in Register.  3.Pushing arguments into the stack.  4.Returning to the calling function.
  • 5. Inline functions can be implemented using the keyword inline.  The inline is a request to the compiler.  The function always can not be inline by the compiler  The complicated functions will not be inline.  Just like a macro, but different from macro.
  • 6.  C++ proposes a new feature called inline functions.  By using this we can eliminate the cost of calls to small functions.  An inline function is a function that in expanded in line when it is invoked.  Inline function must be defined before they are called.  Inline keyword sends a request, not a command to the compiler.
  • 8. The inline function is just a code replacement instead of the function call.  There is a need of stack storage and other special mechanism for function call and return.  The stack storage is used to store the return value and return address for function call and return process.  And while passing the parameter the stack storage needed to store the parameter values, and from the stack area the values moved to data area.
  • 9. While using the inline function, there is no need of these operations, because of code replacement.  The compiler can do inline on either a high-level intermediate representation or a low-level intermediate representation.  In either case, the compiler simply computes the arguments, stores them in variables corresponding to the function's arguments, and then inserts the body of the function at the call site.
  • 10.  In an application, if the time complexity is to be reduced means the inline function can be used.  The overhead of calling and returning from the function, parameter manipulation (push/ pop) are reduced.  Increases locality of references by utilizing instruction cache.  After inline the compiler may perform the optimization of the code by boycott the dead codes. i.e., the unused code lines that will always get true or false or not performing any modification in execution.
  • 11. Example:  int pred(int x) { if (x == 0) return 0; else return x - 1; } Before inline  int f(int y) { return pred(y) + pred(0) + pred(y+1); } After inline int f(int y) { int temp = 0; if (y == 0) temp += 0; else temp += y - 1; /*1*/ if (0 == 0) temp += 0; else temp += 0 - 1; /*2*/ if (y+1 == 0) temp += 0; else temp += (y + 1) - 1; /*3*/ return temp; }
  • 12. The temp += 0 statements in the lines marked (1), (2) and (3) do nothing. The compiler can remove them.  The condition 0 == 0 is always true, so the compiler can replace the line marked (2) with the consequent, temp += 0 (which does nothing).  The compiler can rewrite the condition y+1 == 0 to y == -1.  The compiler can reduce the expression (y + 1) - 1 to y (assuming wraparound overflow semantics)  The expressions y and y+1 cannot both equal zero. This lets the compiler eliminate one test.  These are all the actions the compiler may do for the better resulting of the inline function implementation
  • 13. In C++ the function can be inline using the keyword ‘inline’.  The member function of a class and the global functions are also possible to declare as inline.  The compiler may or may not make the function as an inline we requested. It is up to the compiler.  The advanced provisions made in Visual C++ to make a function as inline. The pragmas implemented.  The recursive functions also may be implemented as inline in VC++.
  • 14. #include<iostream.h> int main() #include<conio.h> { class samp samp k; { clrscr(); int h; k.display(); public: cout<<"hi friends...n"; samp(){h=0;}; k.display(); void display(); getch(); }; return 0; inline void samp::display() { } cout<<h<<endl; }
  • 15. #include<iostream.h> return 0; #include<conio.h> } void display() { output : cout<<"nnin Inline in Inline function functionn"; } int main() { clrscr(); display(); getch();
  • 16. Macro invocations do not perform type checking, or even check that arguments are well-formed, whereas function calls usually do.  Macro can not return any value where the function return.  Some constructs may be difficult through macro, but can be done using inline function.  Error correction in function is somewhat easier than Macro.  Many compilers can also inline expand some recursive functions; recursive macros are typically illegal.
  • 17.  Many compilers can also inline expand some recursive functions; recursive macros are typically illegal.  Major drawback is macros are not Functions  Usual error checking does not occur during compilation.
  • 18. Some constructs may be difficult through macro, but can be done using inline function. inline double cube(double a) { return(a*a*a); } The above function invoked by statements like OUTPUT: 1.cube(3.0); 27 2.cube(2.5+1.5); 64
  • 19. d  = cube(2.5+1.5); { return(d*d*d); } Output: 64 This result will differ in macro definitions. So, by this way also inline function is useful.
  • 20. The inline function must be simple and small.  If the code size is too large, some compiler will not treat that as inline function.  The inline expansion can not be recognized by the programmer. If the function is not treated as inline, then it will take care of compiler as normal function.
  • 21.  In the following situation inline expansion may not work: 1.For function returning values, if a loop, a switch or goto exists. 2.For function not returning values, if a return statement exists. 3.If function contains static variables. 4.If inline function are recursive.
  • 22. Wherever the execution time is need to reduce, there the inline function can be implemented. But the one thing is the memory consumption for storing the file may be increased.  For example, assume while writing Operating system the inline function may be used to reduce the execution time. The simple and small code can be inline.  And in mobile application, the memory available is more than enough. But application response time is a criteria means we can use inline function.
  • 23. Whenever the memory consumption is a constraint then inline will not be applied there as a solution., because inline will paste the code then and there, where the function call.  For some embedded applications, the execution time can be extended, but memory is restricted.  If the function is larger size, the speed benefits of inline function will reduce.  Sometimes the overhead of the function call becomes small compared to execution of the function.  On that time the benefits of inline function may be lost
  • 24. The inline function is a special concept., which is normally implemented in all C++ compilers and versions. But based on the compiler version and vendor the inline consideration and conformation differs. Some compilers may accept the function declared as inline to do inline expansion. Some compiler won’t.