reprinted from:
http://www.ccidnet.com/2010/0709/2110463.shtml
1. Macros do simple string substitution ( Note that the substitution of strings is not the substitution of other types of parameters, and the arguments of a function are passed with a data type and can be of various types.
2. The parameter substitution of a macro is handled directly without calculation, and the function call is to pass the value of the argument to the parameter, since it is a value that is calculated naturally.
3. Macros are made before compiling, that is, replacing the macro name with the macro body before compiling it, and the function is obviously compiled and then called when it is executed. Therefore, the macro occupies the compile time, and the function occupies the time of execution.
4. The macro parameter is not a memory space, because it is only the substitution of the string, and the function call parameter passing is the concrete variable between the information passing, the formal parameter as a function of the local variables, obviously occupies memory.
5. Function call is to pay a certain amount of time and space overhead, because the system in the call function, to keep the scene, and then into the called function to execute, call, and then return to the central function, at this time to restore the scene, these operations, obviously in the macro is not.
inline function: The so-called inline function is a very simple function "inline" to call his program code, the only thing to do is to avoid the above mentioned 5th, the purpose is to save the original function call time and space overhead. But it must be noted that: As an inline function, the function body must be very simple, can not contain loops, conditions, selection and other complex structure, otherwise it can not be used as an inline function. In fact, even if you do not specify a function as an inline function, some compiled systems will automatically handle a very simple function as an inline function, and for complex functions, even if you specify him as an inline function, the system will ignore it. The difference between a
function and a macro function is that the macro function takes up a lot of space and the function takes up time. What you need to know is that the function call is to use the system stack to save the data, if the compiler has a stack check option, generally in the head of the function will embed some assembly statements to check the current stack, while the CPU will save and restore the current scene in the function call, for the stack and the stack operation, so the function call needs a Some CPU time. The macro function does not exist for this problem. Macro functions are only embedded in the current program as pre-written code, and do not produce function calls, so it is only occupied space, when the same macro function is called frequently, the phenomenon is particularly prominent.
The difference between a macro function and a function