SlideShare a Scribd company logo
2
Most read
6
Most read
10
Most read
INLINE FUNCTIONS & MACROS
Designed by,
Anand K
InlineFunctions
 Similar to Macros
 Function code is expanded at the point of
function call at compile time.
 Parsed by the compiler.
 Inline functions follow all the protocols of
type safety enforced on normal functions.
 Expressions passed as arguments to inline
functions are evaluated once.
InlineFunctions
 It is declared by using keyword “inline” before
the function prototype.
 Argument types are checked and necessary
conversions are performed correctly.
 The compiler performs return type checking,
function signature before putting inline
functions into the symbol table.
 They can be overloaded to perform the right
kind of operation for the right kind of data.
InlineFunctions
 Can be used for debugging a program as they are
expanded at compile time and a break point can
be placed at the inline function definition.
 We can do step by step debugging.
 Inline functions can access class’s member data.
 Inline functions may or may not be expanded by
the compiler.
 It can be defined inside or outside the class.
 Inline functions pass arguments by value., just
like regular functions.
InlinefunctionsVsRegularfunctions
 The difference between an inline function and
a regular function is that whenever the
compiler finds a call to an inline function, it
writes a copy of the compiled function
definition.
 With a regular function, a normal function call
is generated.
 Inline functions looks like regular functions.
Macros
 Preprocessor directive provided by C.
 Declared by #define.
 Macros are expanded by preprocessor at
precompile time.
 Expressions passed are arguments are evaluated
more than once.
 Good for declaring constants.
 Provide textual substitution.
 Each time the macro name is encountered with
arguments, the arguments used in its definition
are replaced by the actual arguments found.
Macros
 Macros are more error prone as compared to
inline functions.
 The parameters are not typed. The macro
works for any objects of arithmetic type.
 No error checking is done during compilation.
 e.g.. You can pass strings to a macro that does
some integer arithmetic.
 Cannot be used for debugging as they are
expanded at pre-compile time.
Macros
 The preprocessor has no permission to access
member data of a class and are thus useless even
if used within a class.
 Thus they cannot even be used as member
functions.
 Macros are always expanded.
 It cannot be defined inside the class.
 Macros don’t pass by value.
 Expressions passed into macros are not always
evaluated before entering the macro body.
Macros
 Expressions may expand inside the macro so
that their evaluation precedence is different
from what you expect.
 C++ preprocessor implements macros by
using simple textual replacements.
DifferencebetweenMacrosandInline
functions
 Inline functions take defined type arguments
whereas Macros can take any type as
arguments.
 Macros are expanded by the preprocessor
and then compilation takes place.
 Macros are expanded by C preprocessor.
 Inline functions are parsed by the compiler.
 The program size increases with both macros
and inline functions.
Samplecode.Copyandpasteit in any
C/C++ Editortoseeresults.
 #include<stdio.h>
 #define SUM(x) x*x
 #define SUM1(x) (x)*(x)
 #define SUM2(x) x++ * x++
 #define SUM3(x) (x++)*(x++)
 #define toupper(a) ((a) >= 'a' && ((a) <= 'z')?((a)-('a'-'A')):(a))
 #define max(c,d) (c>d?c:d)
 #define max1(a,b) ((a<b)?b:a)
 int main()
 {
 int y=3;
 int z=10;
 char ch;
 int f=1,e=2;
 printf("rnhello world!");
 printf("rn%d",y);
 int j= SUM(y);
 printf("rn%d",j);
 printf("rn");
 printf("rn%d",y);
 int k= SUM1(y);
 printf("rn%d",k);
 printf("rn");
 printf("rn%d",y);
 int i= SUM(++y);
 printf("rn%d",i);
 printf("rn");
 printf("rn%d",y);
 int a= SUM(y++);
 printf("rn%d",a);
 printf("rn");
 printf("rn%d",y);
 int l= SUM2(y);
 printf("rn%d",l);
 printf("rn");
 printf("rn%d",y);
 int m= SUM3(y);
 printf("rn%d",m);
 printf("rn");
 int g=max(f++,e++);
 printf("rn%d,%drn",f,e);
 printf("rnMax of 10 and 30 isrn");
 int h=max1(41,40);
 printf("rn%drn",h);
 printf("rnEnter a character:rn");
 ch=toupper(getc(stdin));
 printf("rn%c",ch);
 getch();
 return 0;
 }

More Related Content

What's hot (20)

PPTX
Unit1 principle of programming language
Vasavi College of Engg
 
PPTX
Turing machine - theory of computation
Rubaya Mim
 
PDF
Time and Space Complexity
Ashutosh Satapathy
 
PPTX
What is a Variable in C Language? | Variable Declaration and initialization.pptx
Han Ni
 
PPT
RECURSION IN C
v_jk
 
PPT
Lecture1616_16827_2D Clipping.ppt
GaganvirKaur
 
PDF
Algorithms Lecture 7: Graph Algorithms
Mohamed Loey
 
PDF
Animation ppt
Ashok Mannava
 
PPTX
Dag representation of basic blocks
Jothi Lakshmi
 
PPTX
Templates in C++
Tech_MX
 
PDF
9 python data structure-2
Prof. Dr. K. Adisesha
 
PPTX
Lexical analysis - Compiler Design
Muhammed Afsal Villan
 
PDF
Array data structure
maamir farooq
 
PPTX
Array sorting
ALI RAZA
 
PPTX
Principal source of optimization in compiler design
Rajkumar R
 
PPTX
Database System Architectures
Information Technology
 
PPTX
Python- Regular expression
Megha V
 
PPT
Regular Languages
parmeet834
 
PDF
Relational algebra in dbms
Vignesh Saravanan
 
DOCX
GE3151 problem solving and python programming - Syllabus
Fatima Michael College of Engineering and Technology
 
Unit1 principle of programming language
Vasavi College of Engg
 
Turing machine - theory of computation
Rubaya Mim
 
Time and Space Complexity
Ashutosh Satapathy
 
What is a Variable in C Language? | Variable Declaration and initialization.pptx
Han Ni
 
RECURSION IN C
v_jk
 
Lecture1616_16827_2D Clipping.ppt
GaganvirKaur
 
Algorithms Lecture 7: Graph Algorithms
Mohamed Loey
 
Animation ppt
Ashok Mannava
 
Dag representation of basic blocks
Jothi Lakshmi
 
Templates in C++
Tech_MX
 
9 python data structure-2
Prof. Dr. K. Adisesha
 
Lexical analysis - Compiler Design
Muhammed Afsal Villan
 
Array data structure
maamir farooq
 
Array sorting
ALI RAZA
 
Principal source of optimization in compiler design
Rajkumar R
 
Database System Architectures
Information Technology
 
Python- Regular expression
Megha V
 
Regular Languages
parmeet834
 
Relational algebra in dbms
Vignesh Saravanan
 
GE3151 problem solving and python programming - Syllabus
Fatima Michael College of Engineering and Technology
 

Viewers also liked (20)

PPTX
Inline function
Tech_MX
 
PPTX
Varnish caching technique
Pankaj Chauhan
 
PPTX
Cache memory
maamir farooq
 
PPT
Lec37
Nikhil Chilwant
 
PPT
Dynamic programming 2
Roy Thomas
 
PPTX
Routing and routing algorithms
Bhatt Aadil
 
PPT
Loader
jayashri kolekar
 
PPT
Network Layer
Rutwik Jadhav
 
PPTX
Routing algorithm
Bushra M
 
PPTX
Inline function in C++
Learn By Watch
 
PPTX
Linking in MS-Dos System
Satyamevjayte Haxor
 
PPTX
Ch 4 linker loader
Malek Sumaiya
 
PPTX
Direct linking loaders
Satyamevjayte Haxor
 
PPT
Routing algorithm network layer
sambhenilesh
 
PPT
Routing
Amit Pandey
 
PPTX
Direct linking loader
babyparul
 
PPT
Network Layer
Ghaffar Khan
 
PDF
Memory organization
Dr. Abhineet Anand
 
PPT
Routing algorithm
farimoin
 
PPTX
Linkers
Tech_MX
 
Inline function
Tech_MX
 
Varnish caching technique
Pankaj Chauhan
 
Cache memory
maamir farooq
 
Dynamic programming 2
Roy Thomas
 
Routing and routing algorithms
Bhatt Aadil
 
Network Layer
Rutwik Jadhav
 
Routing algorithm
Bushra M
 
Inline function in C++
Learn By Watch
 
Linking in MS-Dos System
Satyamevjayte Haxor
 
Ch 4 linker loader
Malek Sumaiya
 
Direct linking loaders
Satyamevjayte Haxor
 
Routing algorithm network layer
sambhenilesh
 
Routing
Amit Pandey
 
Direct linking loader
babyparul
 
Network Layer
Ghaffar Khan
 
Memory organization
Dr. Abhineet Anand
 
Routing algorithm
farimoin
 
Linkers
Tech_MX
 
Ad

Similar to Inline functions & macros (20)

PPTX
1614745770521_vivek macros.pptx
VivekSaini87
 
PDF
Module 05 Preprocessor and Macros in C
Tushar B Kute
 
PPTX
INLINE FUNCTIONS IOT68.pptx
ZalakPatel228771
 
PDF
Computer_Programming_Part_II_Segment_02.pdf
et243047
 
PPSX
Chapter-4_OOP aare temi Lena na petna chho loda
kongshi9999
 
PDF
05 -working_with_the_preproce
Hector Garzo
 
PPTX
Preprocessor directives in c language
tanmaymodi4
 
PPTX
Preprocessor directives in c laguage
Tanmay Modi
 
PPTX
Function in C++, Methods in C++ coding programming
estorebackupr
 
PDF
(8) cpp abstractions separated_compilation_and_binding_part_i
Nico Ludwig
 
PPTX
INLINE FUNCTION IN C++
Vraj Patel
 
PPT
Preprocessors
Koganti Ravikumar
 
PPT
Functions in C++
Mohammed Sikander
 
PDF
Preprocessor
Learn By Watch
 
PDF
6 preprocessor macro header
hasan Mohammad
 
PPTX
1 - Preprocessor.pptx
AlAmos4
 
PPTX
CSE240 Macros and Preprocessing
Garrett Gutierrez
 
PDF
inline function
SAURABH SHARMA
 
PDF
ANSI C Macros
Srikrishnan Suresh
 
PPTX
Inline Functions and Default arguments
Nikhil Pandit
 
1614745770521_vivek macros.pptx
VivekSaini87
 
Module 05 Preprocessor and Macros in C
Tushar B Kute
 
INLINE FUNCTIONS IOT68.pptx
ZalakPatel228771
 
Computer_Programming_Part_II_Segment_02.pdf
et243047
 
Chapter-4_OOP aare temi Lena na petna chho loda
kongshi9999
 
05 -working_with_the_preproce
Hector Garzo
 
Preprocessor directives in c language
tanmaymodi4
 
Preprocessor directives in c laguage
Tanmay Modi
 
Function in C++, Methods in C++ coding programming
estorebackupr
 
(8) cpp abstractions separated_compilation_and_binding_part_i
Nico Ludwig
 
INLINE FUNCTION IN C++
Vraj Patel
 
Preprocessors
Koganti Ravikumar
 
Functions in C++
Mohammed Sikander
 
Preprocessor
Learn By Watch
 
6 preprocessor macro header
hasan Mohammad
 
1 - Preprocessor.pptx
AlAmos4
 
CSE240 Macros and Preprocessing
Garrett Gutierrez
 
inline function
SAURABH SHARMA
 
ANSI C Macros
Srikrishnan Suresh
 
Inline Functions and Default arguments
Nikhil Pandit
 
Ad

Recently uploaded (20)

PDF
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
PDF
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
PDF
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
PDF
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PPTX
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
PPTX
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
PPTX
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 

Inline functions & macros

  • 1. INLINE FUNCTIONS & MACROS Designed by, Anand K
  • 2. InlineFunctions  Similar to Macros  Function code is expanded at the point of function call at compile time.  Parsed by the compiler.  Inline functions follow all the protocols of type safety enforced on normal functions.  Expressions passed as arguments to inline functions are evaluated once.
  • 3. InlineFunctions  It is declared by using keyword “inline” before the function prototype.  Argument types are checked and necessary conversions are performed correctly.  The compiler performs return type checking, function signature before putting inline functions into the symbol table.  They can be overloaded to perform the right kind of operation for the right kind of data.
  • 4. InlineFunctions  Can be used for debugging a program as they are expanded at compile time and a break point can be placed at the inline function definition.  We can do step by step debugging.  Inline functions can access class’s member data.  Inline functions may or may not be expanded by the compiler.  It can be defined inside or outside the class.  Inline functions pass arguments by value., just like regular functions.
  • 5. InlinefunctionsVsRegularfunctions  The difference between an inline function and a regular function is that whenever the compiler finds a call to an inline function, it writes a copy of the compiled function definition.  With a regular function, a normal function call is generated.  Inline functions looks like regular functions.
  • 6. Macros  Preprocessor directive provided by C.  Declared by #define.  Macros are expanded by preprocessor at precompile time.  Expressions passed are arguments are evaluated more than once.  Good for declaring constants.  Provide textual substitution.  Each time the macro name is encountered with arguments, the arguments used in its definition are replaced by the actual arguments found.
  • 7. Macros  Macros are more error prone as compared to inline functions.  The parameters are not typed. The macro works for any objects of arithmetic type.  No error checking is done during compilation.  e.g.. You can pass strings to a macro that does some integer arithmetic.  Cannot be used for debugging as they are expanded at pre-compile time.
  • 8. Macros  The preprocessor has no permission to access member data of a class and are thus useless even if used within a class.  Thus they cannot even be used as member functions.  Macros are always expanded.  It cannot be defined inside the class.  Macros don’t pass by value.  Expressions passed into macros are not always evaluated before entering the macro body.
  • 9. Macros  Expressions may expand inside the macro so that their evaluation precedence is different from what you expect.  C++ preprocessor implements macros by using simple textual replacements.
  • 10. DifferencebetweenMacrosandInline functions  Inline functions take defined type arguments whereas Macros can take any type as arguments.  Macros are expanded by the preprocessor and then compilation takes place.  Macros are expanded by C preprocessor.  Inline functions are parsed by the compiler.  The program size increases with both macros and inline functions.
  • 11. Samplecode.Copyandpasteit in any C/C++ Editortoseeresults.  #include<stdio.h>  #define SUM(x) x*x  #define SUM1(x) (x)*(x)  #define SUM2(x) x++ * x++  #define SUM3(x) (x++)*(x++)  #define toupper(a) ((a) >= 'a' && ((a) <= 'z')?((a)-('a'-'A')):(a))  #define max(c,d) (c>d?c:d)  #define max1(a,b) ((a<b)?b:a)  int main()  {  int y=3;  int z=10;  char ch;  int f=1,e=2;  printf("rnhello world!");  printf("rn%d",y);  int j= SUM(y);  printf("rn%d",j);  printf("rn");
  • 12.  printf("rn%d",y);  int k= SUM1(y);  printf("rn%d",k);  printf("rn");  printf("rn%d",y);  int i= SUM(++y);  printf("rn%d",i);  printf("rn");  printf("rn%d",y);  int a= SUM(y++);  printf("rn%d",a);  printf("rn");  printf("rn%d",y);  int l= SUM2(y);  printf("rn%d",l);  printf("rn");  printf("rn%d",y);  int m= SUM3(y);  printf("rn%d",m);  printf("rn");
  • 13.  int g=max(f++,e++);  printf("rn%d,%drn",f,e);  printf("rnMax of 10 and 30 isrn");  int h=max1(41,40);  printf("rn%drn",h);  printf("rnEnter a character:rn");  ch=toupper(getc(stdin));  printf("rn%c",ch);  getch();  return 0;  }