Assertions

This API defines 2 assertion macros. One is named ZTD_ASSERT, and the other is named ZTD_ASSERT_MESSAGE. The first takes only one or more conditional tokens, the second takes a mandatory message token as the first parameter, and then one or more conditional parameters.

The user can override the behavior of each of these by defining both of ZTD_ASSERT_USER and ZTD_ASSERT_MESSAGE_USER.

When debug mode is detected and user-defined assertions are not macro-defined, then a default implementation is used. Typically, these:

  • check the condition, and if it is true:

    • print (std::cerr or fprintf(stderr, ...), depending on the language) a message including line, file, etc.; and,

    • exit the program cleanly (std::terminate or exit, depending on the language)

Note that no side-effects should ever go into assertions, because assertions can be compiled to do nothing.

ZTD_ASSERT(...)

A macro for asserting over a given (set of) conditions.

Remark

The conditions must result in a value that is convertible to a boolean in a boolean context. This macro does nothing when ZTD_DEBUG is not detected. (It will still (void)-cast the used items, to prevent unused warnings.) If the condition is not reached, this function will perform either a user-defined action or terminate/exit (not abort).

Parameters
  • ...[in] The conditional expressions to check against.

ZTD_ASSERT_MESSAGE(_MESSAGE, ...)

A macro for asserting over a given (set of) conditions.

Remark

The conditions must result in a value that is convertible to a boolean in a boolean context. This macro does nothing when ZTD_DEBUG is not detected. (It will still (void)-cast the used items, to prevent unused warnings.) If the condition is not reached, this function will perform either a user-defined action or terminate/exit (not abort).

Parameters
  • _MESSAGE[in] The message to pass through.

  • ...[in] The conditional expressions to check against.