- 论坛徽章:
- 0
|
The unary operator # causes "stringization" of a formal parameter in a macro definition. Here is an example of its use:
- #define message_for (a, b) \
- printf (#a " and " #b ": We love you!\n")
- int main () {
- message_for (Carole, Debra);
- return 0;
- }
复制代码
When the macro is invoked, each parameter in the macro definition is replaced by its corresponding argument, with the # causing the argument to be surrounded by double quotes.Thus,after the preprocessor pass, we obtain
- int main () {
- printf ("Carole" " and " "Debra" ": We love you!\n");
- return 0;
- }
复制代码
The binary operator ## is used to merge tokens. Here is an example of how the operator is used:
- #define X(i) x ## i
- X(1) = X(2) = X(3);
复制代码
After the preprocessor pass, we are left with the line
x1 = x2 = x3; |
|