pjsip 中 define 的妙用

define 语法

define func funcA
上面的就是简单的替换 func 替换funcA的使用

看下pjsip的用法


// 案例: PJ_LOG(2, (__FILE__, "current value is %d", value));



#define PJ_LOG(level,arg)   do { \
                    if (level <= pj_log_get_level()) { \
                    pj_log_wrapper_##level(arg); \
                    } \
                } while (0)

//上面就是func 替换 funcA 的形式 但是,
//此时 ## 连接符 2 替换level , arg 代表 (__FILE__, "current value is %d", value)
// 所以最后形式 pj_log_wrapper_2(arg)  ,  此时arg 在编译之前不会替换
// ps: \ 还有 ## 是不同使用场景的连接符


#if PJ_LOG_MAX_LEVEL >= 2
    #define pj_log_wrapper_2(arg)   pj_log_2 arg //这里虽然有空格,不符合define 语法,注意下面分析
    /*
    替换结果
    pj_log_wrapper_2(arg)  pj_log_2 (__FILE__, "current value is %d", value)   函数

    不能纠结空格 
    pj_log_2 arg 相当于函数 pj_log_2 (__FILE__, "current value is %d", value)
    有像函数形式一样也有空格

    */


    PJ_DECL(void) pj_log_2(const char *src, const char *format, ...);
    /*
    所以 这里 src 指向 _FILE_ 字符串内容  format 就指向 "current value is %d", value  内容
    */



作者:贱贱的杨
从此你们的路上不会孤单,还有贱贱的我

猜你喜欢

转载自blog.csdn.net/engineer_james/article/details/79239233