【发布时间】:2014-10-10 08:17:07
【问题描述】:
我正在编写一个程序,我想轻松地打开/关闭我的调试代码。这个程序不是生产级别的——它是用于编程比赛的。
我只有一个文件main.cpp,所以我认为调试变量可能是可以接受的。我考虑过使用全局变量,如下:
bool DEBUG = true;
int main()
{
if (DEBUG)
{
// print debug statements and other debug code
}
// rest of program...
但是,我收到警告说我的 DEBUG 变量从未使用过,if (DEBUG) 始终评估为假。或者,我可以将我的 DEBUG 变量带入 main() 方法:
int main()
{
bool DEBUG = true;
if (DEBUG)
{
// print debug statements and other debug code
}
// rest of program...
然后我收到编译器警告“条件始终为真. Any suggestions on how to easily switch on/off myDEBUG”代码?对编译器问题的解释会很好。
【问题讨论】:
-
通常这些标志是使用一些外部刺激设置的。例如reg 键设置。您应该对此进行探索。
标签: c++ debugging scope global-variables