首页 > 宏中使用函数名的问题

宏中使用函数名的问题

看下面的代码

#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...

【热门文章】
【热门文章】