Difference Between Macros and Inline Functions

Inline function is an important addition in C++. These inline functions mostly are not called and is expanded in line at the invocation place. Hence, these functions are called inline functions. To define a function as inline function, precede function definition with “inline” keyword. Check inline function for more information.

Macros are preprocessor directive which simply substitute patterns in the code. They can be used anywhere in the code, and these are expanded before compilation begins.

(more…)
Difference Between Macros and Inline Functions Read More

Inline Function Explained With Simple Example

Inline function is an important addition in C++. These inline functions mostly are not called and is expanded in line at the invocation place. Hence, these functions are called inline functions. To define a function as inline function, precede function definition with “inline” keyword. These functions are almost similar to Macros in C.
For eg:

inline int sum (int a, int b);
(more…)
Inline Function Explained With Simple Example Read More

Difference between constexpr vs inline functions

constexpr functions are implicitly inline functions only. However, inline functions are simply removes the overhead of function calls by pasting the function body at the called place. But, these code will be executed at run time. Hence, performance gain will be because of reduced function calls.

constexpr functions are evaluated at the compile time to ensure no computation at runtime and hence gives better performance optimization.

Any member functions can be made inline. However, only those functions whose return types and argument types are all of literal types.

For more information related to constexpr click here.

Difference between constexpr vs inline functions Read More