#运算符用于在预编译期将宏参数转换为字符串
#include <stdio.h>
#define CONVERS(x) #x
int main()
{
printf("%s\n", CONVERS(Hello world!));
printf("%s\n", CONVERS(100));
printf("%s\n", CONVERS(while));
printf("%s\n", CONVERS(return));
return 0;
}
通过命令: gcc -E f1.c -o f1.i
实例分析6-1 #运算符在宏中的妙用
#include <stdio.h>
#define CALL(f, p) (printf("Call function %s\n", #f), f(p))
int square(int n)
{
return n * n;
}
int f(int x)
{
return x;
}
int main()
{
printf("1. %d\n", CALL(square, 4));
printf("2. %d\n", CALL(f, 10));
printf("1. %d\n", (printf("Call function %s\n