macro Vs inline
2011-01-06 08:51
489 查看
The C/C++ style, macros without arguments should look like variable or other identifiers, macros with arguments should look like function calls.
so any difference between macro and inline?
#define SQUARE(x) ((x)*(x))
inline int square(int x) {return x*x;}
macro may not work properly if the actually argument is an expression with side efforts, for example:
SQUARE(i++)
The inline is newly added to C standard from C99, the previous C compiler might not support it
inline checks type of argument and does conversion, it might not work properly sometimes.for example:
double f = square(1.5);
and in C++, we can use template for avoid this issue, like
inline const _T square_t(_T x) {return x*x;}
so any difference between macro and inline?
#define SQUARE(x) ((x)*(x))
inline int square(int x) {return x*x;}
macro may not work properly if the actually argument is an expression with side efforts, for example:
SQUARE(i++)
The inline is newly added to C standard from C99, the previous C compiler might not support it
inline checks type of argument and does conversion, it might not work properly sometimes.for example:
double f = square(1.5);
and in C++, we can use template for avoid this issue, like
inline const _T square_t(_T x) {return x*x;}
相关文章推荐
- C++OOP基础知识点1)——inline vs macro
- Inline vs macro
- Inline vs. External Javascript
- Inline asp.net tags vs code behind
- display: block vs inline vs inline-block
- Some MACRO In VS Project Setting
- 浮动布局 VS 基于display:inline-block的列表布局
- C/C++: Inline function, calloc vs malloc
- An Inline Function is As Fast As a Macro(《Using the GNU Compiler Collection (GCC)》)
- C/C++: Inline function, calloc vs malloc
- macro与inline的区别 What is the difference between macro and inline?
- C/C++: Inline function, calloc vs malloc
- C/C++: Inline function, calloc vs malloc
- display:inline vs float
- Kernel开发 - SubmittingPatches,有关ifdef和static inline & macro
- In C++, what’s the difference between an inline function and a macro?
- C/C++: Inline function, calloc vs malloc
- C/C++: Inline function, calloc vs malloc
- Block-Level vs. Inline Elements(块级元素和内联元素对比)
- how to enable #ifdef macro in the command line of make?