msdn中是这样描述ASSERT的:ASSERTASSERT( booleanExpression )
Parameters
booleanExpression
Specifies an expression (including pointer values) that evaluates to nonzero or 0.
Remarks
Evaluates its argument. If the result is 0, the macro prints a diagnostic message and aborts the program. If the condition is nonzero, it does nothing.
The diagnostic message has the form
assertion failed in file <name> in line <num>
where name is the name of the source file, and num is the line number of the assertion that failed in the source file.
In the Release version of MFC, ASSERT does not evaluate the expression and thus will not interrupt the program. If the expression must be evaluated regardless of environment, use the VERIFY macro in place of ASSERT.
Note This function is available only in the Debug version of MFC.
Example
// example for ASSERT
CAge* pcage = new CAge( 21 ); // CAge is derived from CObject.
ASSERT( pcage!= NULL )
ASSERT( pcage->IsKindOf( RUNTIME_CLASS( CAge ) ) )
// Terminates program only if pcage is NOT a CAge*.
在开发过程中我们可以假设只要程序运行正确,某一条件肯定成立。如不成立,那么我们可以断言程序肯定出错。
在这种情况下我们可以利用ASSERT来设定断言。ASSERT宏的参数是一个逻辑表达式,在程序运行过程中,若该逻辑表达式为真,则不会发生任何动作,若此表达式为假,系统将弹出一个对话框警告你,并停止程序的执行。同时要求你作出选择:Abort,Ignore, Retry。若你选择Abort,系统将停止程序的执行;若你选择Ignore 系统将忽略该错误,并继续执行程序;若你选择Retry ,系统将重新计算该表达式,并激活调试器。
同TRACE宏一样,ASSERT宏只DEBUG版本中起作用,在RELEASE版本中ASSERT宏将被忽略