AssertAssert() statementsAssert() statements can help you narrow down where your problems are happening. An assert statment like assert(x>0) asserts a condition that should be true of you program was written correctly, i.e. bug free.
For example, the code
will produce the error message:
if, at that point in your code, the variable age wasn't 65.Assertion failed: age == 65, file security.c, line xx Here's a complete example of using assert() :
Output:linux3[83] % a.out ~\/~\/~ ~\/~\/~\/~\/~\/~\/~\/~\/~\/~\/~\/~\/~\/~\/~ ~\/~\/~\/~\/~\/~\/~\/~\/~\/~\/~\/~\/~\/~\/~ ~\/~\/~\/~\/~\/~\/~\/~\/~\/~\/~\/~\/~\/~\/~ ~\/~\/~\/~\/~\/~\/~\/~\/~\/~\/~\/~\/~\/~\/~ ~\/~\/~\/~\/~\/~\/~\/~\/~\/~\/~\/~\/~\/~\/~ ~\/~\/~\/~\/~\/~\/~\/~\/~\/~\/~\/~\/~\/~\/~ a.out: sample.c:24: main: Assertion `i < 101' failed. ~\/~\/~\/~\/~\/~\/~\/~\/~\/~\/Abort linux3[84] % Turning off Assert()Assertions are for debugging and should not be left enabled in a program after debugging.
There are two ways to do this
CSEE | 201 | 201 S'05 | lectures | news | resources | help |
|