assert macro | Checks an assertion at runtime |
void assert (int expression) |
If enabled, the assert macro ensures the expression is true (nonzero). If so, nothing happens, and execution continues normally. If the expression evaluates to , assert prints a message to the standard error file and calls abort . The format of the message is implementation-defined, but it includes a textual representation of expression and the filename and line number where the assert call appears (that is, the values of the _ _FILE_ _ and _ _LINE_ _ macros).
If disabled, the assert macro does not evaluate expression and has no effect.
abort function in <cstdlib> , throw keyword
NDEBUG macro | Enables or disables compilation of assertions |
#define NDEBUG #include <cassert> |
The NDEBUG macro is not defined by <cassert> or anywhere else in the standard C++ library. Instead, you can define the macro before including the <cassert> header to disable the assert macro.
In one source file, you can define and undefine NDEBUG multiple times, each time followed by #include <cassert> , to enable or disable the assert macro multiple times in the same source file.
assert macro