Static and Dynamic assertion debugging, static and dynamic assertion debugging
Debugging is often required when writing a program. The following describes static and dynamic assertions debugging and common built-in macros.
Built-in macros:
_ FILE _ // output FILE name
_ LINE _ // row
_ DATE _ // DATE
_ TIME _ // TIME
_ FUNCTION _ // FUNCTION name
static_assert( constant-expression, string-literal );
Static assertions are used during compilation. Therefore, the value of the first parameter must be determined during compilation, such as the length. If the second parameter is a prompt message. If the expression value of the first parameter is false, an error occurs during compilation and
The second parameter value.
void assert( int expression );
Dynamic assertions are used when the program is running. If the expression result is false, the program is interrupted.
# Include <iostream> # include <assert. h> using namespace std; void test (int mouth) {assert (mouth >=1 & mouth <= 12 ); // dynamically assert cout <__file __< <endl; // output FILE name cout <__line __< endl; // cout <__date __< <endl; // DATE cout <__time __< endl; // TIME cout <__function __< endl; // function name} int main () {int mouth = 12; static_assert (sizeof (void *) = 4, "64-bit code generation is not supported. "); // static assertions. test (mouth); cin is not supported for 64-bit systems. get (); return 0 ;}