c++ - 宏中使用函数名的问题
本文介绍了c++ - 宏中使用函数名的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
看下面的代码
#include <stdio.h>
#include <stdlib.h>
#define call_optimized(function, arguments) {\
printf("\n-------------"); \
printf("\n\tCALL %s\n", #function); \
function arguments; \
printf("-------------\n"); \
}
void foo(char *str) {
printf("%s\n", str);
}
void foo2(char *str1, char *str2) {
printf("%s, %s\n", str1, str2);
}
int main(void) {
printf("FIRST call_optimized\n");
call_optimized(foo, ("hell world"));
printf("\nSECOND call_optimized");
call_optimized(foo2, ("hell", "world"));
system("pause");
return 0;
}
输出(手打):
FIRST call_optimized
------------------
CALL foo
hello world
------------------
CALL foo2
hello, world
------------------
宏中 printf("\n\tCALL %s\n", #function);
输出函数名为什么要在前面加上 #
符号?求解释~
解决方案
这里的出现在define里面的#表示一个宏的连接
传送见这里
http://www.cnblogs.com/qinfengxiaoyue/ar...
这篇关于c++ - 宏中使用函数名的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文