More On Functions
Inline Functions
- Functions with small code can be declared as inline.
- Wherever an inline function is called, actual function code will be replaced
- Syntax: Put keyword inline before function definition and not in declaration. For e.g.
void swap(int& a,int& b); //declaration
inline void swap(int& a,int& b) //defintion
{
int temp;
temp = a;
a = b;
b= temp;
}
Inline Function Vs Macros
- Unlike inline functions, macros do not have type-checking and also do not check if arguments are well-formed.
- You cannot return a value as computation result in a macro.
- Macro uses textual substitution, so there may be side-effects and inefficiencies due to re-evaluation of arguments and order of operators.
- Macro expanded code is difficult to understand for compilation errors.
- Debugging information for inline functions is more helpful
- Sometimes, required construct cannot be written using macros or may be it will awkward to do so.
Points to Ponder
- Member functions defined inside the class definition are inline by default.
- Compiler decides which function to use as inline. So, even if you have declared a function inline, compiler can treat it as normal function. In this case, compiler will use calling instead of replacing the function code at the calling places.
- Inline functions may increase the performance significantly.
- May because inline functions increases code size to be compiled and therefore compilation time.
Bjarne Stroustrup suggests to avoid use of macros and instead use inline functions for frequently executed small functions.
Page Author
From Here You Can…
Information
- 794 Views
- 0 Comments
Most Recent Related Content
- Lesson
- Avatar

- Title
- PHP: Using Arrays
- Body
- Arrays are one of the most used properties in php, arrays are like a containe...
- Author
- Lesson
- Avatar

- Title
- K12 Lesson Plan Repository
- Body
- This is a resource that I wanted to share across groups so I made it a lesson...
- Author
- Lesson
- Avatar

- Title
- Lessons, Discussions and Debates - What's the Difference?
- Body
- I’m having a provocative dialogue with a LearnHub colleague about what ...
- Author
- Lesson
- Avatar

- Title
- Interesting Lessons
- Body
- Why not spend less time learning in class and more online?
- Author
- Lesson
- Avatar

- Title
- 7 Places Teachers Can Turn Your Expertise Into CA$H Online
- Body
- Spring, 2008: A recession looms large, credit continues to tighten, sales a...
- Author
- Lesson
- Avatar

- Title
- Opportunity Knocking ... Anybody Home?
- Body
- I’m having a tough time making any kind of sense of this, myself…...
- Author
- Lesson
- Avatar

- Title
- Tips For How To Enjoy Participating in a Voicethread
- Body
- To be an active Voicethreader, start by carefully working your way through a ...
- Author
- Lesson
- Avatar

- Title
- Open Source Software Licenses Abridged Part 1
- Body
- When I jumped into the Linux/open-source world I didn’t know nor care about ...
- Author
Published In…
Computer Science
Software Carpentry
Java
Agile Software Development
Everything PHP
Web 2.0
Technical Writing, Training, Publishing
Open Source
tech
Game Development
Computer Basics
PHP and MySQL
Google
J2EE
Computer Hardware
GNU & Linux
Social Media
C++
Programming Languages
Software Architecture
Computer Science Learners
singh's community
This work is public domain.