宏定義:
#define SMART_LOG(fmt, args...) \
ULOG("[%d]" fmt, __LINE__, ## args);
使用示例:
SMART_LOG("count =%d,time=%d\n", count ,time);
等價於==》ULOG("[%d]" "count =%d,time=%d\n", __LINE__,count ,time);
#include<cstdio>
#include<iostream>
using namespace std;
#define f(a,b) a##b
#define d(a) #a
#define s(a) d(a)
int main()
{
int xy = 10;
cout<< f(x,y) << endl;
puts( d(f(a,b));
puts( s(f(a,b) );
}
輸出
10
f(a,b)
ab
分析:
1 # 使在#後的首個參數返回爲一個帶引號的字符串; ##把兩個符號連起來是把##前後兩個符號連接起來
2,不以"#"開頭的,先展開參數a,然後是替換代碼:puts(s(f(a,b)));-->puts(s(ab))-->puts(d(ab))-->puts("ab")
3,以"#"開頭的,直接替換,不展開:puts(d(f(a,b)))-->puts("f(a,b)")