2009年7月22日 星期三

Inline v.s. Macro

Inline 是在c++ 中加進來以改進c macro 的缺點

不同於macro, Inline 有透過 compiler 做編譯

因而擁有Compiler 所提供的型別確認(Type checcking)的好處

例如:

#define ABS(a) ((a>0)?(a):(-a))

inline int ABS(int a){
if(a>0)
return a;
else
return -a;
}

沒有留言:

張貼留言