https://blog.csdn.net/liuchunjie11/article/details/80558877一、总结 1、#操作符 1:#操作符用于预处理阶段,将宏参数转换为字符串,只有宏定义中使用(#define) 使用方法: #define STRING(x) #x printf("%s\n",STRING(Hello World!)); 2、##操作符 1:##操作符用于预处理阶段,将粘连两个标识符,只有宏定义中使用(#define) 使用方法: #define CONNECT(a,b) a##b int CONNECT(a,1); //int a1 a1 = 2; 二、代码测试 想一个问题啊,怎样打印任意函数名出来? #define CALL(f,p) (printf("Call function %s\n",#f),f(p)) //typedef struct _tag_Student Student; #define STRUCT(type) typedef struct _tag_##type type;\ //************演示#运算符使用方法*************// printf("%s\n",STRING(Hello World)); printf("%s\n",STRING(100)); printf("%s\n",STRING(while)); printf("%s\n\n",STRING(return)); //************演示#打印任意函数名称方法********// printf("result = %d\n",result); printf("result = %d\n\n",result); //************演示##运算符使用方法************// printf("%d\n",NAME(1)); //打印name1 = 1 printf("%d\n",NAME(2)); //打印name2 = 2 //************演示##定义结构体特殊用法*********// printf("s1.name = %s s1.id = %d\n",s1.name,s1.id); printf("s2.name = %s s2.id = %d\n",s2.name,s2.id);
程序比较简单,都有注释 参考资料《狄泰软件C语言进阶》
|