Assertions and static assertions. More...
Macros | |
#define | mi_static_assert(expr) |
Compile time assertion that raises a compilation error if the constant expression expr evaluates to false . More... |
|
#define | mi_base_assert(expr) (static_cast<void>(0)) |
Base API assertion macro (without message). More... |
|
#define | mi_base_assert_msg(expr, msg) (static_cast<void>(0)) |
Base API assertion macro (with message). More... |
|
#define | mi_base_assert_enabled |
Indicates whether assertions are actually enabled. More... |
|
#define | MI_BASE_ASSERT_FUNCTION ("unknown") |
Expands to a string constant that describes the function in which the macro has been expanded. More... |
|
Assertions and static assertions.
#include <mi/base/assert.h>
The Base API supports quality software development with assertions. They are contained in various places in the Base API include files.
These tests are switched off by default to have the performance of a release build. To activate the tests, you need to define the two macros mi_base_assert and mi_base_assert_msg before including the relevant include files. Defining only one of the two macros is considered an error.
See also Base API Assertions Base API assertion macro (without message). If By default, this macro does nothing. You can (re-)define this macro to perform possible checks and diagnostics within the specification given in the previous paragraph. Indicates whether assertions are actually enabled. This symbol gets defined if and only if you (re-)defined mi_base_assert and mi_base_assert_msg. Note that you can not simply test for mi_base_assert or mi_base_assert_msg, since these macros get defined in any case (if you do not (re-)define them, they evaluate to a dummy statement that has no effect). Expands to a string constant that describes the function in which the macro has been expanded. This macro can be used as diagnostic in addition to the standard If possible, lets the asserts support function names in their message. Base API assertion macro (with message). If The By default, this macro does nothing. You can (re-)define this macro to perform possible checks and diagnostics within the specification given in the previous paragraph. Compile time assertion that raises a compilation error if the constant expression Example usage: This compile-time assertion can be used inside as well as outside of functions. If this assertion fails the compiler will complain about applying the You may define the macro mi_static_assert(expr) yourself to customize its behavior, for example, to disable it. Macro Definition Documentation
#define mi_base_assert
(
expr)
(static_cast<void>(0))
expr
evaluates to true
this macro shall have no effect. If expr
evaluates to false
this macro may print a diagnostic message and change the control flow of the program, such as aborting the program or throwing an exception. But it may also have no effect at all, for example if assertions are configured to be disabled.
#define mi_base_assert_enabled
#define MI_BASE_ASSERT_FUNCTION ("unknown")
LINE
and FILE
values. For compilers that do not support such function name diagnostic the string "unknown"
will be used.
#define mi_base_assert_msg
(
expr,
msg
)
(static_cast<void>(0))
expr
evaluates to true
this macro shall have no effect. If expr
evaluates to false
this macro may print a diagnostic message and change the control flow of the program, such as aborting the program or throwing an exception. But it may also have no effect at all, for example if assertions are configured to be disabled.msg
text string contains additional diagnostic information that may be shown with a diagnostic message. Typical usages would contain "precondition"
or "postcondition"
as clarifying context information in the msg
parameter.
#define mi_static_assert
(
expr)
expr
evaluates to false
. mi_static_assert(sizeof(char) == 1);
sizeof
operator to an undefined or incomplete type on the line of the assertion failure.