![]() |
HEL_ASSERT
mechanism evaluates an expression and, when the result is FALSE
, displays an errorscreen and aborts the program execution until you press a specific button. The error-screen displays several informations where in the source the assertion failed. This includes: ![]() |
Macro:
HEL_ASSERT(expression, message ...)
Parameter:
expression : Expression that evaluates to TRUE or FALSE message : Message to display when expression is FALSE
The HEL_ASSERT
macro is typically used to identify logic errors during program development by implementing the expression argument to evaluate to FALSE
only when the program is operating incorrectly.
After debugging is complete, assertion checking can be turned off by undefine HAM_DEBUGGER
in 'ham/include/mygba.h':
#define HAM_DEBUGGER
Example:
In this program the SetHeroState
function uses HEL_ASSERT
to test if the passed pointer pHero
is NULL
and State
is lesser than HERO_STATE_ITEMS
.
typedef struct _THero { int State; }THero; enum { HERO_STATE_JUMP=0, HERO_STATE_WALK, HERO_STATE_STAY, HERO_STATE_ITEMS }HERO_STATE; THero gHero; void SetHeroState(THero *pHero, u32 State); void main(int argc, char *argv[]) { // Initialization and whatever ... // Does not raise an error! SetHeroState(&gHero, HERO_STATE_STAY); // Displays an error, because we // pass NULL as first parameter!! SetHeroState(NULL, HERO_STATE_STAY); } void SetHeroState(THero *pHero, u32 State) { HEL_ASSERT(pHero != NULL, "pHero must not be NULL"); HEL_ASSERT(State < HERO_STATE_ITEMS, "State must not be greater than HERO_STATE_ITEMS"); pHero->State = State; }
The HEL_ASSERT
mechanism evaluates an expression and, when the result is FALSE
, displays an errorscreen and aborts the program execution until you press a specific button. The error-screen displays several informations where in the source the assertion failed. This includes:
![]() |
Macro:
HEL_ASSERT(expression, message ...)
Parameter:
expression : Expression that evaluates to TRUE or FALSE message : Message to display when expression is FALSE
The HEL_ASSERT
macro is typically used to identify logic errors during program development by implementing the expression argument to evaluate to FALSE
only when the program is operating incorrectly.
After debugging is complete, assertion checking can be turned off by undefine HAM_DEBUGGER
in 'ham/include/mygba.h':
#define HAM_DEBUGGER
Example:
In this program the SetHeroState
function uses HEL_ASSERT
to test if the passed pointer pHero
is NULL
and State
is lesser than HERO_STATE_ITEMS
.
typedef struct _THero { int State; }THero; enum { HERO_STATE_JUMP=0, HERO_STATE_WALK, HERO_STATE_STAY, HERO_STATE_ITEMS }HERO_STATE; THero gHero; void SetHeroState(THero *pHero, u32 State); void main(int argc, char *argv[]) { // Initialization and whatever ... // Does not raise an error! SetHeroState(&gHero, HERO_STATE_STAY); // Displays an error, because we // pass NULL as first parameter!! SetHeroState(NULL, HERO_STATE_STAY); } void SetHeroState(THero *pHero, u32 State) { HEL_ASSERT(pHero != NULL, "pHero must not be NULL"); HEL_ASSERT(State < HERO_STATE_ITEMS, "State must not be greater than HERO_STATE_ITEMS"); pHero->State = State; }