KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
Assertions

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.
 

Detailed Description

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

Macro Definition Documentation

◆ assert

#define assert ( e)
Value:
((e) ? (void)0 : __assert(__FILE__, __LINE__, #e, NULL, __ASSERT_FUNC))

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

Parameters
eA value or expression to be evaluated as true or false.

◆ assert_msg

#define assert_msg ( e,
m )
Value:
((e) ? (void)0 : __assert(__FILE__, __LINE__, #e, m, __ASSERT_FUNC))

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.

Parameters
eA value or expression to be evaluated as true or false.
mA message (const char *).

Typedef Documentation

◆ assert_handler_t

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

Parameters
fileThe filename where the assertion happened.
lineThe line number where the assertion happened.
exprThe expression that raised the assertion.
msgA custom message for why the assertion happened.
funcThe function name from which the assertion happened.
See also
assert_set_handler

Function Documentation

◆ assert_set_handler()

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.

Returns
The old assertion handler so it may be restored later if appropriate.
See also
assert_handler_t