In C, there is a very good feature called inline functions. This function is similar to a C or C macro. To use inline functions, we must specify the inline
keyword. We can use this type of function anywhere, but we should follow some guidelines.
When can I use inline functions?
Inline functions can be used in the position of macros (#define)
For small functions, we can use inline functions. It creates faster code and smaller executable files.
We can use inline functions when the function is small and called frequently.
When should you avoid using inline functions?
We should not use I/O bound functions as inline functions.
When a large amount of code is used in a function, we should avoid using inline functions.
Inline functions may not work properly when using recursion.
One thing we must remember is that inlining is not a command, but a request. So we ask the compiler to use inline functions. If the compiler decides that the current function should not be an inline function, it can convert it to a normal function.
The above is the detailed content of When to use inline functions in C/C++ and when not to use it?. For more information, please follow other related articles on the PHP Chinese website!