ASSERT宏定义如下#define ASSERT(f) \ do \ { \ if (!(f) && AfxAssertFailedLine(THIS_FILE, __LINE__)) \ AfxDebugBreak(); \ } while (0) \ASSERT(逻辑表达式)如果括号中的逻辑表达式值为假的话,会弹出调试命令窗口,提示具体在哪个文件的哪一行发生了断言错误!
ASSERT Evaluates an expression, and displays a diagnostic message if the expression is FALSE. Ignored in retail builds.SyntaxASSERT( cond );ParameterscondExpression to evaluate.ResIn debug builds, if the expression is FALSE, this macro displays a message box with the text of the expression, the name of the source file, and the line number. The user can ignore the assertion, enter the debugger, or quit the application.ExampleASSERT(rtStartTime <= rtEndTime);
do \
{ \
if (!(f) && AfxAssertFailedLine(THIS_FILE, __LINE__)) \
AfxDebugBreak(); \
} while (0) \ASSERT(逻辑表达式)如果括号中的逻辑表达式值为假的话,会弹出调试命令窗口,提示具体在哪个文件的哪一行发生了断言错误!
Evaluates an expression, and displays a diagnostic message if the expression is FALSE. Ignored in retail builds.SyntaxASSERT(
cond
);ParameterscondExpression to evaluate.ResIn debug builds, if the expression is FALSE, this macro displays a message box with the text of the expression, the name of the source file, and the line number. The user can ignore the assertion, enter the debugger, or quit the application.ExampleASSERT(rtStartTime <= rtEndTime);
契约式编程讲的比较清楚,建议可以先看看这类书。
一个函数由前置条件、后置条件和不变式组成。在VC中,我们可以通过断言来保证这三个条件。可以大大提高了软件的质量。
:)
如果参数为FALSE的时候,会给出源程序的什么地方出现这一断言的信息