Community
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.
Advertisement
Page Author
From Here You Can…
Information
- 1500 Views
- 0 Comments
Most Recent Related Content
- Lesson
- Avatar

- Title
- PHP: Making all letters caps
- Body
- A simple way of making all letters into capitals is to use PHP’s inbuil...
- Author
- Lesson
- Avatar

- Title
- Linux, Apache, MySQL and PHP (LAMP) Server configuration
- Body
- IntroductionThis lesson will be about the usual configuration of a LAMP serve...
- Author
- Lesson
- Avatar

- Title
- PHP: Simple Guestbook Tutorial
- Body
- The purpose of this tutorial is to show you how to create a very simple g...
- Author
- Lesson
- Avatar

- Title
- Paaniyon ka mausam
- Body
- Phir koi ghazl sunaanay ko mera dil chahe Phir ik shamma jalaanay ko mera ...
- Author
- Presentation
- Avatar

- Title
- How To Succed...
- Description
- Hi, this is a very nice presentation and the credit goes to the original auth...
- 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
- Where are you from?
- Body
- Author
- Presentation
- Avatar

- Title
- C programming (From Basics to Advanced Concepts)
- Description
- Friends, this presentation of 50 slides will help you to quickly revise right...
- 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.