In any program, there are some conditions that should never occur. These conditions include division by zero, writing to the null pointer, and so forth. You want to be informed whenever such conditions occur in your program, and furthermore, you want know exactly where they occur.
The C language comes with such a construct, in the form of the assert() command. The assert() command tests the condition inside its parentheses, and if the condition is false, it takes these steps:
1. Prints the text of the condition that failed.
2. Prints the line number of the error.
3. Prints the source code file that contains the error.
4. Causes the program to terminate with an error condition.
No comments:
Post a Comment