From: http://msdn.microsoft.com/en-us/library/09dwwt6y%28VS.80%29.aspx
The double-number-sign or "token-pasting" operator (## ), which is sometimes called the "merging" operator, is used in both object-like and function-like macros. It permits separate tokens to be joined into a single token and therefore cannot be the first or last token in the macro definition.
If a formal parameter in a macro definition is preceded or followed by the token-pasting operator, the formal parameter is immediately replaced by the unexpanded actual argument. Macro expansion is not performed on the argument prior to replacement.
Then, each occurrence of the token-pasting operator in token-string is removed, and the tokens preceding and following it are concatenated. The resulting token must be a valid token. If it is, the token is scanned for possible replacement if it represents a macro name. The identifier represents the name by which the concatenated tokens will be known in the program before replacement. Each token represents a token defined elsewhere, either within the program or on the compiler command line. White space preceding or following the operator is optional.
This example illustrates use of both the stringizing and token-pasting operators in specifying program output:
If a macro is called with a numeric argument like
the macro yields
which becomes
// preprocessor_token_pasting.cpp
#include <stdio.h>
#define paster( n ) printf_s( "token" #n " = %d", token##n )
int token9 = 9;
int main()
{
paster(9);
}
Output
token9 = 9
本文详细介绍了C/C++预处理符中的令牌拼接运算符(##),展示了如何使用该运算符将独立的标识符合并成单一标识符,并通过示例解释了其在宏定义中的应用。
117

被折叠的 条评论
为什么被折叠?



