- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
When to use inline function and when not to use it in C/C++?
In C++, there is one good feature called inline function. This kind of functions are like the macros of C or C++. To use inline functions, we have to specify the inline keyword. We can use this type of functions anywhere, but we should follow some guideline.
When inline can be used?
Inline functions can be used in the place of macros (#define)
For small functions we can use inline functions. It creates faster code and smaller executables.
When functions are small and called very often, we can use inline.
When we should avoid the use of inline?
We should not use functions that are I/O bound as inline functions.
When large code is used in some function, then we should avoid the inline.
When recursion is used, inline function may not work properly.
One point we have to keep in mind, that inline is not a command. It is a request. So we are requesting the compiler to use inline functions. If the compiler decides that the current function should not be an inline function, it can convert it into normal function.
- When to use an inline function in Kotlin?
- When to use new operator in C++ and when it should not be used?
- When to use extern in C/C++
- When to use tuples in C#?
- When to use C over C++, and C++ over C?
- When to use virtual destructors in C++?
- When to use references vs. pointers in C/C++
- When to use i++ or ++i in C++?
- When to use an abstract class and when to use an interface in Java?
- What is a smart pointer and when should I use it in C++?
- What does “unsigned” in MySQL mean and when to use it?
- When to use MyISAM and InnoDB?
- When to use $(document).ready() and when $(window).load() in jQuery?
- What is explicit implementation and when to use in the interface in C#?