【发布时间】:2019-10-04 00:55:18
【问题描述】:
我想自定义fprintf 函数以启用/禁用日志记录
我的项目使用 Makefile。
#define ENABLE_LOG
void log(fmt, ...){
#ifdef ENABLE_LOG
va_list vargs;
va_start(vargs, fmt);
fprintf(stderr, vargs);
va_end(vargs);
#endif
}
log("Test"); # build error
log("TEST %d", 1); # build error
如何创建自定义 log 函数,该函数可以使用 ENABLE_LOG 启用/禁用
【问题讨论】:
-
以上有什么不能用的?
-
请创建一个minimal reproducible example 并解释究竟是什么不起作用。对我来说唯一突出的是
fmt需要一个类型,可能是const char* fmt。 -
要添加到@alterigel 的评论中,您也不能在函数之外使用通用语句,例如对
log的调用。 -
另外请花一些时间阅读the help pages、阅读the SO tour、阅读how to ask good questions以及this question checklist。当询问构建错误时,请在您的问题中包含实际错误,并完整完整地复制粘贴(作为文本)。