First say the difference between macros and functions:
1. The macro does a simple string substitution (note that the substitution of strings is not a substitute for other types of parameters), whereas 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. Macro before compiling, that is, the macro body replace the macro name, and then compile, and the function is obviously compiled after the execution of the call. Therefore, the macro occupies the compile time, and the function occupies the time of execution.
4. Macro parameters are not accounted for in memory space, because it is only to do the substitution of strings, and function calls when the parameter is passed between the specific variables of the information passing, formal parameters as a function of the local variables, obviously occupy memory.
5. Function call is to pay a certain 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.
Now see inline functions:
The so-called "inline function" is a very simple function "inline" to invoke his program code, the only thing to do is to avoid the 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 and cannot contain loops, conditions, Select a complex structure, otherwise it cannot be 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 stack of the system 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 is also in the function call to save and restore the current scene, for the stack and stack operation, so, function calls require 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.
1, using the macro than the use of functions in the program's size and speed are better.
2. The parameter of the function must be declared as a specific type, so he can only use it on the appropriate type of expression. Conversely, macros are type-independent.
3, the disadvantage of the macro is: every time you use a macro, a macro-defined code to be inserted into the program.
The difference between a macro and a function