MDL SDK API nvidia_logo_transpbg.gif Up
Base API Assertions

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...
 

Detailed Description

Assertions and static assertions.

Include File:
#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 Configuration Options in general.

Macro Definition Documentation

 mi_base_assert

#define mi_base_assert (   expr)    (static_cast<void>(0))

Base API assertion macro (without message).

If 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.

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.

See also
Base API Configuration Options for Assertions

 mi_base_assert_enabled

#define mi_base_assert_enabled

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).

 MI_BASE_ASSERT_FUNCTION

#define MI_BASE_ASSERT_FUNCTION   ("unknown")

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 __LINE__ and __FILE__ values. For compilers that do not support such function name diagnostic the string "unknown" will be used.

If possible, lets the asserts support function names in their message.

 mi_base_assert_msg

#define mi_base_assert_msg (   expr,
  msg 
)    (static_cast<void>(0))

Base API assertion macro (with message).

If 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.

The 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.

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.

See also
Base API Configuration Options for Assertions

 mi_static_assert

#define mi_static_assert (   expr)
Value:
typedef mi::base::static_assert_test<static_cast<int>( \
sizeof(mi::base::static_assert_failure<static_cast<bool>((expr))>))> \
MI_BASE_JOIN(static_assert_instance, __LINE__) mi_static_assert_attribute

Compile time assertion that raises a compilation error if the constant expression expr evaluates to false.

Example usage: mi_static_assert(sizeof(char) == 1);

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 sizeof operator to an undefined or incomplete type on the line of the assertion failure.

You may define the macro mi_static_assert(expr) yourself to customize its behavior, for example, to disable it.