Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between macro & inline function with respect to execution speed?

Tags:

c++

inline

How complier treats inline functions over macros to reduce execution time?

like image 459
Chandrakant Avatar asked Dec 12 '22 16:12

Chandrakant


2 Answers

The compiler is also allowed to not inline the function if doing so would be faster, whereas the compiler cannot not inline a macro. In addition, inline functions are miles safer than macros.

like image 88
Puppy Avatar answered Jan 14 '23 14:01

Puppy


Inline functions are very similar to macros because they both are expanded at compile time, but the macros are expanded by the preprocessor, while inline functions are parsed by the compiler.

like image 31
garima Avatar answered Jan 14 '23 13:01

garima