next up previous contents
Next: The PRE_CONDITION and Up: Types of Assertions Previous: Types of Assertions

The ASSERT statement

An ASSERT statement is used to check the value of a single variable at a particular location in the program. It may be placed at any point that a C++ / Java statement could be placed. In the following example, an ASSERT statement is used to insure that the variable x does not have a negative value after the assignment statement.

. . . .
x = y ;
ASSERT( x >= 0, "x has a negative value") ;
cout << "Value of x is " << x << endl ;
. . . .

ASSERT statements are useful to verify that values computed within methods/functions are within acceptable bounds. An ASSERT statement may only be used as a Definition Placed assertion.



Roger Gima
Tue Jan 20 16:43:17 EST 1998