2010年12月5日 星期日

# (stringizing) and ##(merging) operator

#include <stdio.h>


// reference "多型與虛擬" p.184~185 (author 侯捷)

// # (stringizing operator): 將巨集參數轉換為字串常數
#define stringer(x) printf(#x "\n")

// ## (merging operator or token-pasting operator): 把兩個 token 合併成一個 token 再交由編譯器去 parsing
#define paster(n) printf("token" #n "=%d",token##n)


void test_stringer()
{
stringer(hello    world);
}

void test_paster()
{
int token9 = 9;
paster(9);
}

int main()
{
test_stringer();
test_paster();
}

沒有留言:

張貼留言