Compile-time expansion |
Macro functions are expanded by the preprocessor at the compile time. |
Inline functions are expanded by the compiler. |
Argument Evaluation |
Expressions passed to the Macro functions might get evaluated more than once. |
Expressions passed to Inline functions get evaluated once. |
Parameter Checking |
Macro functions do not follow strict parameter data type checking. |
Inline functions follow strict data type checking of the parameters. |
Ease of debugging |
Macro functions are hard to debug because it is replaced by the pre-processor as a textual representation which is not visible in the source code. |
Easier to debug inline functions which is why it is recommended to be used over macro functions. |
Example |
#define SQUARENUM(A) A * A -> The macro functions are expanded at compile time. Hence, if we pass, the output will be evaluated to 3+2*3+2 which gets evaluated to 11. This might not be as per our expectations. |
inline squareNum(int A){return A * A;} -> If we have printf(squareNum(3+2)); , the arguments to the function are evaluated first to 5 and passed to the function, which returns a square of 5 = 25. |