c++之调试帮助
assert()
assert(expr): 如果表达式为假, assert输出信息并终止程序。如果为真,assert什么也不做。
NDEBUG
#include <iostream>
int main(int argc, char** argv)
{
int a = 1, b = 2;
if (a < b)
{
std::cerr << "Error occur in " << __FILE__ << " File; " << std::endl
<< "in " << __func__ << " Function; at " << __LINE__ << " Line; " << std::endl
<< "Compile on " << __DATE__ << " at " << __TIME__ << std::endl;
}
return 0;
}
Error occur in /home/liuzhiyang/workspace/unit_test/src/unit_test/src/cpp_test.cpp File;
in main Function; at 35 Line;
Compile on Dec 25 2018 at 19:18:01
__FILE__
: 存放文件名的字符串字面值
__LINE__
:存放当前行号的整形字面值
__func__
: 存放当前函数名的字符串字面值
__DATA__
: 存放文件编译日期的字符串字面值
__TIME__
: 存放文件编译时间的字符串字面值