/*
* 1.字符串化, Creating Strings from Macro Arguments: The # Operator
* Within the replacement part of a function-like macro, the # symbol becomes a preprocessing operator that converts tokens into strings.
* 把 #x 转变成字符串 "x", 其中x是传进宏的参数
*
* 2.标识符黏合, Preprocessor Glue: The ## Operator
* The ## operator combines two tokens into a single token
*/#include <stdio.h>#define TEST1(x) printf("the square of x is %d\n", (x)*(x))#define TEST2(x) printf("the square of " #x " is %d\n", (x)*(x))#define PRINT_XN(n) printf("a" #n " = %d\n", a ## n)int main(int argc, charconst *argv[])
{
int i = 4;
TEST1(i);
TEST1(2 + 3);
TEST2(i);
TEST2(2 + 3); // printf("the square of ""2 + 3"" is %d\n", (2 + 3)*(2 + 3))
TEST2((2 + 3));
int a1 = 50;
int a2 = 60;
PRINT_XN(1); // printf("a1 = %d\n", a1);
PRINT_XN(2);
PRINT_XN(1+1);
printf("good""bye""\n");
return0;
}
// 运行结果:
$ ./a.out
the square of x is 16
the square of x is 25
the square of i is 16
the square of 2 + 3 is 25
the square of (2 + 3) is 25
a1 = 50
a2 = 60
a1+1 = 51
goodbye
预处理#define中的符号和字符串问题# 字符串化,即把传进宏的参数转变成相应string## 标识符胶水,即把两个token黏合为一个token/* * 1.字符串化, Creating Strings from Macro Arguments: The # Operator * Within the replacement part of a function-like macr