问题
Possible Duplicate:
Inline functions vs Preprocessor macros
In C++ the inline function qualifier basically replaces the function as a #define directive, rather than making the function being called over and over again. Thus reducing overhead time, but at the same time increasing program size.
If my understanding of inline function is correct, what is the different, of inline and #define?
回答1:
inline
is only a hint, which the compiler is free to ignore#define
s aren't a compiler-level feature—they're substitutions, not functions- In order to safely put multiple statements in a macro, you must wrap it in
do { ... } while(0)
. - The parameters of a macro are re-evaluated every time they're used.
- Names in the caller scope are accessible to the macro
- In order to safely put multiple statements in a macro, you must wrap it in
来源:https://stackoverflow.com/questions/6402613/inline-function-vs-define