断言与忽略断言

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 // 忽略断言
 
 
 

 

 
posted @ 2021-09-21 14:34  hbg-rohens  阅读(169)  评论(0编辑  收藏  举报