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
- 986 Views
- 0 Comments
Most Recent Related Content
- 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
- 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
- Web 2.0 Tools
- Body
- Layout of the course: The course on web 2.0 tools for instructi...
- Author
- Lesson
- Avatar

- Title
- Automated Builds Using Make
- Body
- IntroductionMost languages require you to compile them before they can be run...
- Author
- Lesson
- Avatar

- Title
- Tests and Discussion Questions - What's the Difference?
- Body
- “Virtually all learning difficulties that children face are caused by adults’...
- Author
- Presentation
- Avatar

- Title
- "Jumpstart" LIVE Session 2 - Including Assignments
- Description
- Slides – including assignments- for the second LIVE session of “J...
- Author
- Lesson
- Avatar

- Title
- electronics
- Body
- Author
- Lesson
- Avatar

- Title
- Linkedin Demographics Data
- Body
- LinkedIn Demographic Data Jun08View SlideShare presentation or Upload your ow...
- 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.