c++ - 宏中使用函数名的问题
大家讲道理
大家讲道理 2017-04-17 13:34:06
0
1
365

看下面的代码

#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); 输出函数名为什么要在前面加上 # 符号?求解释~

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(1)
Ty80

The # appearing in define here represents a macro connection
See here for transmission
http://www.cnblogs.com/qinfengxiaoyue/ar...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template