Macro and inline function are very similar. Compiler expands macro where it is called and inline functions are also copied to the place where it is called. They both increase code size as compiler copies object code to the location where these are getting called. However they are not same and differences between macro and inline functions are:
Typed arguments vs untyped arguments
Inline functions take defined typed arguments where as macros can take any type as argument.
Example syntax
inline int swap(int *a, int *b); #define swap(a, b)
Macros are expanded by the preprocessor before compilation takes place. Compiler will refer error messages in expanded macro to the line where the macro has been called.
Compilation error in macro
main.c(11):error C2146: syntax error : missing ';' before identifier 'next_user' Line 5 has the original compilation error
Compilation error in inline function
main.c(6) : error C2146: syntax error : missing ';' before identifier 'next_user'
About our authors: Team EQA
You have viewed 1 page out of 252. Your C learning is 0.00% complete. Login to check your learning progress.