宏关闭的printf语句 [英] Macro to turn off printf statements
问题描述
什么宏可用于关掉printf的语句,而不是删除它们全部部署构建,我只是想将其关闭,跳过他们,不理会他们。
What MACRO can be used to switch off printf statements, rather than removing them all for deployment builds, I just want to switch them off, skip them, ignore them.
编辑:我个人使用gcc,但code是一个更大的项目,该项目将在运行Ubuntu熊猫板被编译的一部分
I personally use gcc, but code is part of a larger project which will be compiled on a Panda board running Ubuntu.
推荐答案
不完全是你问,但我在使用此结构在我的code调试输出时,我没有一个合适的日志系统方便的内容:
Not exactly what you ask for, but I use this construct in my code for debug output when I do not have a proper logging system handy:
#if 1
#define SPAM(a) printf a
#else
#define SPAM(a) (void)0
#endif
因此,我可以做到这一切在我的code
So I can do this all over my code
SPAM(("foo: %d\n", 42));
,然后在#如果<改变
1
到 0
禁用所有的人/ code>以上。
and then disable all of them by changing 1
to 0
in #if
above.
但是,如果你在你写code的,那么你可以去其他的答案,只是重新定义的printf
全部编译器可变参数宏支持。 (话虽这么说,我就觉得有用,从普通的人在code不同的调试打印 - 使用不同的函数名有助于可读性。)
But if you have variadic macro support in all compilers that you write code for, then you may go for other answers and just redefine printf
. (That being said, I find it useful to distinct debugging prints from regular ones in code — using a different function name helps readability.)
请注意,您也可以重定向标准输出
到的/ dev / null的
,但我认为要从运行时开销摆脱为好。
Note that you also can redirect stdout
to the /dev/null
, but I assume that you want to get rid from runtime overhead as well.
这篇关于宏关闭的printf语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!