1. Parameters. Macros define no type restrictions, and function parameters must be defined even if the same functionality is implemented. Eg: #defineMAX (x, y) > (y)? (X):(Y)
2. Efficiency of execution
The function has high efficiency when it passes parameters and return values without a macro definition of a direct substitution statement.
3. Program length
When a macro is defined, a line of code is written, and the function calls a location, and the source code does not grow.
4. Side effects
The return value changes when J + + is passed
#defineMAX (x, y) > (y)? (X):(Y) int a=3;int b=4; MAX (a++,b++); The result is 5.5. Operator precedence affects the result in the macro definition (with the parentheses restriction if necessary). 6. A macro definition cannot define recursion.
This article is from the "Small Stop" blog, please be sure to keep this source http://10541556.blog.51cto.com/10531556/1680261
The difference between a macro definition and a function