#include <OTC/OTC.h> OTCLIB_ASSERT(expression);
OTCLIB_ASSERT()
can be used to aid in program verification.
The macro is used to indicate the expectation that the expression is to
be true at this point in the program. If the expression is
false, an exception of type
OTCERR_AssertionFailure
is thrown.
Compiling with the compiler option -DNDEBUG
effectively deletes OTCLIB_ASSERT()
from the program.
If you are using makeit
, the NDEBUG
symbol is
automatically defined when you use the opt
variant.
Note that the expression evaluated in the condition, should not produce any
side effects, which the program relies upon. If this is done, when
the assertions are compiled out of code, the program may stop functioning
correctly.
OTCLIB_ASSERT(TRUE == FALSE);
If the exception is caught and the information it contains is dumped to the logger, the format of the output will be:
ERROR: Assertion failed ERROR: Location: "_assert.cc", line 33 ERROR: Condition: TRUE == FALSE
The macro may be used in either C or C++ code.
A string literal should not be used as part of the condition as some preprocessors cannot handle converting to a string, a value which has a string in it.