看下面的代码
#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);
输出函数名为什么要在前面加上 #
符号?求解释~
The # appearing in define here represents a macro connection
See here for transmission
http://www.cnblogs.com/qinfengxiaoyue/ar...