ASSERT preprocessing macros
Assert is a preprocessing macro, so-called preprocessing is actually a preprocessing variable that behaves like an inline function, and an Assert macro uses an expression as its condition:
ASSERT (expr)
The first is to evaluate expr, and if its value is false, assert the output information and terminate the execution of the program, and do nothing if true . The Assert macro is defined in the cassert header file , because it is a macro, so there is no scope and namespace for the argument to be used directly. You do not need to include namespaces.
As with pre-processing variables, the macro name must be unique within the program, and the program containing the Cassert header can no longer define variables, functions, etc. called Assert.
ndebug preprocessing variables
The behavior of an assert depends on the state of a preprocessing variable named ndebug , and if ndebug is defined, the Assert does nothing, and by default there is no Ndebug defined, at which point the assert performs a run-time check, which compares the side
Then, when we do not need to Asser check, do not need to delete the previous Assert statement, as long as the #define NDEBUG .
In addition to the use of assert, we can also use Ndebug to define their own debug code, mainly in the code to do ndebug preprocessing variables are defined by the judgment on it!
void print (int ia[], size_t size) { #ifndef ndebug ..... #endif
The C + + compiler provides the _ _func_ _ variable, we can output the name of the current debug function, and the preprocessor also defines the following name:
_ _file_ _/ / The string literal of the file name _ _line_ _ / ////////////////////////
This allows us to export more and more detailed information when we define our own debug code.
C + + debugging Help