C语言类函数宏的参数

1 view
Skip to first unread message

benegg

unread,
Sep 13, 2009, 11:50:46 AM9/13/09
to online_game_dev
宏很有用, 小心别上瘾.

1. Stringification, 把参数作为C字符串, "#".

#define M(a) #a

M(hello) => "hello"

2. Concatenation, 字面替换和拼接, "##".

#define M(a) a ## _b

M(hello) => hello_b

## 两边可以放空白字符和注释.

参考: Red Hat Enterprise Linux 3: Using cpp, the C Preprocessor

转自: http://www.ideawu.net/blog/?p=416

Reply all
Reply to author
Forward
0 new messages