SlideShare a Scribd company logo
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

Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
Lovely Professional University
 
Function overloading and overriding
Function overloading and overridingFunction overloading and overriding
Function overloading and overriding
Rajab Ali
 
LR Parsing
LR ParsingLR Parsing
LR Parsing
Eelco Visser
 
Compiler design syntax analysis
Compiler design syntax analysisCompiler design syntax analysis
Compiler design syntax analysis
Richa Sharma
 
Code generation
Code generationCode generation
Code generation
Aparna Nayak
 
COMPILER DESIGN
COMPILER DESIGNCOMPILER DESIGN
COMPILER DESIGN
Vetukurivenkatashiva
 
Selection statements
Selection statementsSelection statements
Selection statements
Harsh Dabas
 
Principal source of optimization in compiler design
Principal source of optimization in compiler designPrincipal source of optimization in compiler design
Principal source of optimization in compiler design
Rajkumar R
 
Operator precedence and associativity
Operator precedence and associativityOperator precedence and associativity
Operator precedence and associativity
Dr.Sandhiya Ravi
 
Ternary operator
Ternary operatorTernary operator
Ternary operator
Hitesh Kumar
 
Unit iv(simple code generator)
Unit iv(simple code generator)Unit iv(simple code generator)
Unit iv(simple code generator)
Kalaimathi Vijayakumar
 
Linking in MS-Dos System
Linking in MS-Dos SystemLinking in MS-Dos System
Linking in MS-Dos System
Satyamevjayte Haxor
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
kamal kotecha
 
Ll(1) Parser in Compilers
Ll(1) Parser in CompilersLl(1) Parser in Compilers
Ll(1) Parser in Compilers
Mahbubur Rahman
 
Operators in java
Operators in javaOperators in java
Operators in java
Then Murugeshwari
 
Regular Languages
Regular LanguagesRegular Languages
Regular Languages
parmeet834
 
Chapter 5 -Syntax Directed Translation - Copy.ppt
Chapter 5 -Syntax Directed Translation - Copy.pptChapter 5 -Syntax Directed Translation - Copy.ppt
Chapter 5 -Syntax Directed Translation - Copy.ppt
FamiDan
 
Dijkstra's Algorithm
Dijkstra's Algorithm Dijkstra's Algorithm
Dijkstra's Algorithm
Rashik Ishrak Nahian
 
Parse Tree
Parse TreeParse Tree
Parse Tree
A. S. M. Shafi
 

What's hot (20)

Code optimization
Code optimizationCode optimization
Code optimization
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Function overloading and overriding
Function overloading and overridingFunction overloading and overriding
Function overloading and overriding
 
LR Parsing
LR ParsingLR Parsing
LR Parsing
 
Compiler design syntax analysis
Compiler design syntax analysisCompiler design syntax analysis
Compiler design syntax analysis
 
Code generation
Code generationCode generation
Code generation
 
COMPILER DESIGN
COMPILER DESIGNCOMPILER DESIGN
COMPILER DESIGN
 
Selection statements
Selection statementsSelection statements
Selection statements
 
Principal source of optimization in compiler design
Principal source of optimization in compiler designPrincipal source of optimization in compiler design
Principal source of optimization in compiler design
 
Operator precedence and associativity
Operator precedence and associativityOperator precedence and associativity
Operator precedence and associativity
 
Ternary operator
Ternary operatorTernary operator
Ternary operator
 
Unit iv(simple code generator)
Unit iv(simple code generator)Unit iv(simple code generator)
Unit iv(simple code generator)
 
Linking in MS-Dos System
Linking in MS-Dos SystemLinking in MS-Dos System
Linking in MS-Dos System
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Ll(1) Parser in Compilers
Ll(1) Parser in CompilersLl(1) Parser in Compilers
Ll(1) Parser in Compilers
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Regular Languages
Regular LanguagesRegular Languages
Regular Languages
 
Chapter 5 -Syntax Directed Translation - Copy.ppt
Chapter 5 -Syntax Directed Translation - Copy.pptChapter 5 -Syntax Directed Translation - Copy.ppt
Chapter 5 -Syntax Directed Translation - Copy.ppt
 
Dijkstra's Algorithm
Dijkstra's Algorithm Dijkstra's Algorithm
Dijkstra's Algorithm
 
Parse Tree
Parse TreeParse Tree
Parse Tree
 

Viewers also liked

Inline function
Inline functionInline function
Inline functionTech_MX
 
Varnish caching technique
Varnish caching techniqueVarnish caching technique
Varnish caching technique
Pankaj Chauhan
 
Cache memory
Cache memoryCache memory
Cache memory
maamir farooq
 
Dynamic programming 2
Dynamic programming 2Dynamic programming 2
Dynamic programming 2Roy Thomas
 
Routing and routing algorithms
Routing and routing algorithmsRouting and routing algorithms
Routing and routing algorithms
Bhatt Aadil
 
Loader
LoaderLoader
Network Layer
Network LayerNetwork Layer
Network Layer
Rutwik Jadhav
 
Routing algorithm
Routing algorithmRouting algorithm
Routing algorithm
Bushra M
 
Inline function in C++
Inline function in C++Inline function in C++
Inline function in C++
Learn By Watch
 
Ch 4 linker loader
Ch 4 linker loaderCh 4 linker loader
Ch 4 linker loader
Malek Sumaiya
 
Direct linking loaders
Direct linking loadersDirect linking loaders
Direct linking loaders
Satyamevjayte Haxor
 
Routing algorithm network layer
Routing algorithm  network layerRouting algorithm  network layer
Routing algorithm network layer
sambhenilesh
 
Direct linking loader
Direct linking loaderDirect linking loader
Direct linking loaderbabyparul
 
Routing algorithm
Routing algorithmRouting algorithm
Routing algorithm
farimoin
 
Loaders
LoadersLoaders

Viewers also liked (20)

Inline function
Inline functionInline function
Inline function
 
Varnish caching technique
Varnish caching techniqueVarnish caching technique
Varnish caching technique
 
Cache memory
Cache memoryCache memory
Cache memory
 
Lec37
Lec37Lec37
Lec37
 
Dynamic programming 2
Dynamic programming 2Dynamic programming 2
Dynamic programming 2
 
Routing and routing algorithms
Routing and routing algorithmsRouting and routing algorithms
Routing and routing algorithms
 
Loader
LoaderLoader
Loader
 
Network Layer
Network LayerNetwork Layer
Network Layer
 
Routing algorithm
Routing algorithmRouting algorithm
Routing algorithm
 
Inline function in C++
Inline function in C++Inline function in C++
Inline function in C++
 
Ch 4 linker loader
Ch 4 linker loaderCh 4 linker loader
Ch 4 linker loader
 
Direct linking loaders
Direct linking loadersDirect linking loaders
Direct linking loaders
 
Routing algorithm network layer
Routing algorithm  network layerRouting algorithm  network layer
Routing algorithm network layer
 
Routing
RoutingRouting
Routing
 
Direct linking loader
Direct linking loaderDirect linking loader
Direct linking loader
 
Network Layer
Network LayerNetwork Layer
Network Layer
 
Memory organization
Memory organizationMemory organization
Memory organization
 
Routing algorithm
Routing algorithmRouting algorithm
Routing algorithm
 
Linkers
LinkersLinkers
Linkers
 
Loaders
LoadersLoaders
Loaders
 

Similar to Inline functions & macros

Preprocessor directives in c language
Preprocessor directives in c languagePreprocessor directives in c language
Preprocessor directives in c language
tanmaymodi4
 
Preprocessor directives in c laguage
Preprocessor directives in c laguagePreprocessor directives in c laguage
Preprocessor directives in c laguage
Tanmay Modi
 
PreProcessorDirective.ppt
PreProcessorDirective.pptPreProcessorDirective.ppt
PreProcessorDirective.ppt
Osmania University
 
C programming session6
C programming  session6C programming  session6
C programming session6
Keroles karam khalil
 
C question
C questionC question
C question
Kuntal Bhowmick
 
Task Perform addition subtraction division and multiplic.pdf
Task Perform addition subtraction division and multiplic.pdfTask Perform addition subtraction division and multiplic.pdf
Task Perform addition subtraction division and multiplic.pdf
acsmadurai
 
Preprocessor
PreprocessorPreprocessor
Preprocessor
lalithambiga kamaraj
 
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docxBroncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
curwenmichaela
 
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docxBroncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
hartrobert670
 
Functional programming in TypeScript
Functional programming in TypeScriptFunctional programming in TypeScript
Functional programming in TypeScript
binDebug WorkSpace
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
akreyi
 
Getting started with CATIA V5 Macros
Getting started with CATIA V5 MacrosGetting started with CATIA V5 Macros
Getting started with CATIA V5 Macros
Emmett Ross
 
Chapter 13.1.11
Chapter 13.1.11Chapter 13.1.11
Chapter 13.1.11patcha535
 
Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptx
miki304759
 
Bcsl 031 solve assignment
Bcsl 031 solve assignmentBcsl 031 solve assignment
Unit 5 Part 1 Macros
Unit 5 Part 1 MacrosUnit 5 Part 1 Macros
Unit 5 Part 1 Macros
Arpana Awasthi
 
Introduction to Preprocessors
Introduction to PreprocessorsIntroduction to Preprocessors
Introduction to Preprocessors
Thesis Scientist Private Limited
 
5. Functions in C.pdf
5. Functions in C.pdf5. Functions in C.pdf
5. Functions in C.pdf
santosh147365
 

Similar to Inline functions & macros (20)

Preprocessor directives in c language
Preprocessor directives in c languagePreprocessor directives in c language
Preprocessor directives in c language
 
Preprocessor directives in c laguage
Preprocessor directives in c laguagePreprocessor directives in c laguage
Preprocessor directives in c laguage
 
Pre processor directives in c
Pre processor directives in cPre processor directives in c
Pre processor directives in c
 
PreProcessorDirective.ppt
PreProcessorDirective.pptPreProcessorDirective.ppt
PreProcessorDirective.ppt
 
C programming session6
C programming  session6C programming  session6
C programming session6
 
Preprocessors
PreprocessorsPreprocessors
Preprocessors
 
C question
C questionC question
C question
 
Task Perform addition subtraction division and multiplic.pdf
Task Perform addition subtraction division and multiplic.pdfTask Perform addition subtraction division and multiplic.pdf
Task Perform addition subtraction division and multiplic.pdf
 
Preprocessor
PreprocessorPreprocessor
Preprocessor
 
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docxBroncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
 
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docxBroncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
 
Functional programming in TypeScript
Functional programming in TypeScriptFunctional programming in TypeScript
Functional programming in TypeScript
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
Getting started with CATIA V5 Macros
Getting started with CATIA V5 MacrosGetting started with CATIA V5 Macros
Getting started with CATIA V5 Macros
 
Chapter 13.1.11
Chapter 13.1.11Chapter 13.1.11
Chapter 13.1.11
 
Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptx
 
Bcsl 031 solve assignment
Bcsl 031 solve assignmentBcsl 031 solve assignment
Bcsl 031 solve assignment
 
Unit 5 Part 1 Macros
Unit 5 Part 1 MacrosUnit 5 Part 1 Macros
Unit 5 Part 1 Macros
 
Introduction to Preprocessors
Introduction to PreprocessorsIntroduction to Preprocessors
Introduction to Preprocessors
 
5. Functions in C.pdf
5. Functions in C.pdf5. Functions in C.pdf
5. Functions in C.pdf
 

Recently uploaded

Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
Jelle | Nordend
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
ayushiqss
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024
Sharepoint Designs
 
Software Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdfSoftware Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdf
MayankTawar1
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 

Recently uploaded (20)

Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024
 
Software Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdfSoftware Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdf
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 

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