home | |||
links |
|
||
developer's mag main page article part 1 part 2 part 3 part 4 part 5 part 6 part 7 part 8 |
3 - Tool #2 - Assertions
As a good programmer (aren't we all?) You've likely been exposed to assert() or a variant. Assert is used to, well, assert something: assert(NULL!=ptr); // should never be null! I've been using a modified version for many years now, called ASSERTING(). After recently reading a chapter on assertions in the book 'Game Programming Gems', I realized it was time to add a few features to the lowly assert, resulting in the following call: ASSERTING(int test,const char *message); Redoing the above example would give you: ASSERTING( NULL!=ptr, "should never be null!"); Now, whenever the assertion fails (in this case, when ptr is NULL) the assertion 'fires', and the message "should never be null!" is displayed. ASSERTING isn't a function, but rather a macro; it actually does quite a bit more than the above call implies:
The last feature needs more explanation.
Each failed ASSERTING() displays three buttons
in a window along with the assertion message:
'Continue', 'Ignore This Assert', or 'Exit
Program' ('Break to Debugger' on the emulator).
Continue does nothing, which means the assertion
will fire each time it is executed and fails.
'Ignore This Assert' allows you to turn off
the assertion, preventing future testing.
This can be especially useful for loops,
where you don't need the repeated assertions. |
||
Copyright © 2001-2006 ebmDevMag.com - Legal Notice |