断言与忽略断言

c和c++中使用assert()函数来实现断言。

eg:

#include <stdio.h>
#include <assert.h>

int main()
{
int x = 7;
x = 9;

assert(x==7);

/* Rest of the code */

return 0;
}


执行结果如下:

当执行如下命令时,会去掉assert功能,

#define NDEBUG // 忽略断言
 
 
 
 
原文地址:https://www.cnblogs.com/rohens-hbg/p/15316566.html