KallistiOS git master
Independent SDK for the Sega Dreamcast
|
assert() management and custom handlers More...
Files | |
file | assert.h |
Standard C Assertions. | |
Macros | |
#define | assert(e) |
Standard C assertion macro. | |
#define | assert_msg(e, m) |
assert() with a custom message. | |
Typedefs | |
typedef void(* | assert_handler_t) (const char *file, int line, const char *expr, const char *msg, const char *func) |
Assertion handler type. | |
Functions | |
assert_handler_t | assert_set_handler (assert_handler_t hnd) |
Set an assertion handler to call on a failed assertion. | |
assert() management and custom handlers
KOS maps the standard C assert() mechanism to a default implementation which logs the failed expression as well as the source code context. A secondary assertion mechanism, assert_msg() is also provided for adding a cusom message. You may also override KOS's assertion handler and replace it with your own via assert_set_handler().
#define assert | ( | e | ) |
Standard C assertion macro.
This macro does a standard C assertion, wherein the expression is evaluated, and if false, the program is ultimately aborted using abort(). If the expression evaluates to true, the macro does nothing (other than any side effects of evaluating the expression).
e | A value or expression to be evaluated as true or false. |
#define assert_msg | ( | e, | |
m ) |
assert() with a custom message.
This macro acts the same as the assert() macro, but allows you to specify a custom message to be printed out if the assertion fails.
e | A value or expression to be evaluated as true or false. |
m | A message (const char *). |
typedef void(* assert_handler_t) (const char *file, int line, const char *expr, const char *msg, const char *func) |
Assertion handler type.
The user can provide their own assertion handler with this type. If none is provided, a default is used which ultimately prints out the location of the failed assertion and calls abort().
file | The filename where the assertion happened. |
line | The line number where the assertion happened. |
expr | The expression that raised the assertion. |
msg | A custom message for why the assertion happened. |
func | The function name from which the assertion happened. |
assert_handler_t assert_set_handler | ( | assert_handler_t | hnd | ) |
Set an assertion handler to call on a failed assertion.
The default assertion handler simply will print a message and call abort(). NULL is a valid value and will cause nothing to happen on an assert.