When assert is used for debugging, determine whether a statement is true.
Assert is a macro, not a function. In the assert.h header file of C.
The function of an assert is to evaluate the expression first, if its value is false (that is, 0), then it prints an error message to stderr and then terminates the program by calling abort.
The disadvantage of using assert is that frequent calls can greatly affect the performance of the program and add additional overhead.
1. Verify the legality of the parameters at the beginning of the function
2. Each assert examines only one condition, because when multiple conditions are checked, if the assertion fails, it is not possible to visually determine which condition failed
3. You cannot use a statement that alters the environment, because assert only takes effect in debug, and if you do, you will use the program to run into a problem error: assert (i++ < 100)
This is because if there is an error, such as i=100 before execution, then this statement will not be executed, then i++ This command will not be executed. Correct: Assert (i < 100); i++;
Resources:
http://blog.csdn.net/setone/article/details/5573036
Usage of assert