/*************************************** ******************************
* Function: Test assert
* Author: Samson
* Date: 12/12/2011
* Test Platform:
* GNU Linux version 2.6.29.4
* GCC version 4.4.0 20090506 (Red Hat 4.4.0-4) (GCC)
**************************************** ****************************/
# Include <stdio. h>
# Include <stdlib. h>
# Include <malloc. h>
# Include <assert. h>
Int
Main (INT argc, char * argv [])
{
Assert (argc! = 2 );
Printf ("argc is % d \ n", argc );
Exit (0 );
}
When the condition of assert is false, the program will be interrupted. It is useful for developers to debug and can accurately locate the file with the error: function: row number. When the ndebug macro is not added, the output of this test program is:
A. Out: testassert. C: 9: Main: assertion 'argc! = 2 'failed.
Abandoned
However, when releasing a program version, you do not want to interrupt the program directly. If it is soft, you can use the prompt if statement or print.
The compilation method of the soft version is GCC testassert. C-dndebug.
Run result:
[Root @ UFO testc] #./A. out 2
Argc is 2
The straight-forward version compilation method is GCC testassert. C.
Run result:
[Root @ UFO testc] #./A. out 2
A. Out: testassert. C: 9: Main: assertion 'argc! = 2 'failed.
Abandoned