VARIADIC MACRO

本文介绍了一种使用变参数宏(RENDER_LOG)简化日志记录的方法。通过宏定义,可以将不同数量和类型的参数传递给日志函数,提高代码的灵活性与可读性。

http://en.wikipedia.org/wiki/Variadic_macro

宏的变参写法:比如log常常会用到进行分类,用宏来简化书写,可以这样

#define RENDER_LOG(...) BMLog::GetInstance()->LogToDebug(ELT_Render, __VA_ARGS__)

分析以下报错,告诉我宏该如何修正 vproc_u_dbg.h:24:78: error: __VA_ARGS__ can only appear in the expansion of a C99 variadic macro [-Werror] 24 | #define VPROC_U_DBG_PRINT(level,msg,args...) CAP_DEBUG("[ZL380xx_U]" msg, ##__VA_ARGS__) | ^ hbi_u.c: In function 'HBI_init': vproc_u_dbg.h:24:74: error: pasting "," and "__VA_ARGS__" does not give a valid preprocessing token 24 | #define VPROC_U_DBG_PRINT(level,msg,args...) CAP_DEBUG("[ZL380xx_U]" msg, ##__VA_ARGS__) | ^ hbi_u.c:47:4: note: in expansion of macro 'VPROC_U_DBG_PRINT' 47 | VPROC_U_DBG_PRINT(VPROC_DBG_LVL_FUNC, "%s Entry..\n",__func__); | ^~~~~~~~~~~~~~~~~ In file included from vproc_u_dbg.h:1, from hbi_u.c:20: vproc_u_dbg.h:24:78: error: '__VA_ARGS__' undeclared (first use in this function) 24 | #define VPROC_U_DBG_PRINT(level,msg,args...) CAP_DEBUG("[ZL380xx_U]" msg, ##__VA_ARGS__) | ^~~~~~~~~~~ /home/lgb/sharedfile/nvmp/develop_accesscontrol/nvmp/build_dir/target-aarch64-ca53-linux-gnueabihf-accesscontrol/cap/cap_common.h:30:49: note: in definition of macro 'CAP_DEBUG' 30 | msg_debug(DEBUG_TRACE, __FUNCTION__, __LINE__, fmt); \ | ^~~ hbi_u.c:47:4: note: in expansion of macro 'VPROC_U_DBG_PRINT' 47 | VPROC_U_DBG_PRINT(VPROC_DBG_LVL_FUNC, "%s Entry..\n",__func__); | ^~~~~~~~~~~~~~~~~ vproc_u_dbg.h:24:78: note: each undeclared identifier is reported only once for each function it appears in 24 | #define VPROC_U_DBG_PRINT(level,msg,args...) CAP_DEBUG("[ZL380xx_U]" msg, ##__VA_ARGS__) | ^~~~~~~~~~~
最新发布
10-16
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值