斷言與忽略斷言

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

 

 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章