assert与NDEBUG

assert

assert宏定义在头文件assert.h中,其作用是如果括号内的表达式为假,则报告错误并终止程序运行。

NDEBUG

NDEBUG宏定义可以影响assert的行为,当定义了NDEBUG,就屏蔽掉了assert的功能,例如VS中的Release版本就定义了该宏。

#include "stdafx.h"
#include 
#include 

int main()
{
    int a=1;
    assert(a!=1);
    system("pause");
    return 0;
}

你可能感兴趣的:(assert与NDEBUG)