User`s manual

104 digi.com Debugging with Dynamic C
6.3.10 Assert Macro
The assert macro was introduced in Dynamic C 8.51. The Dynamic C implementation of assert follows the
ANSI standard for the NDEBUG macro, but differs in what the macro is defined to be so as to save code
space (ANSI specifies that assert is defined as ((void)0) when NDEBUG is defined, but this generates a
NOP in Dynamic C, so it is defined to be nothing).
Pros The assert macro is self-checking software. It lets you explicitly state something
is true, and if it turns out to be false, the program terminates with an error mes-
sage. At the time of this writing, this link contained an excellent write-up on the
assert macro:
http://www.embedded.com/story/OEG20010311S0021
Cons Side effects can occur if the assert macro is not coded properly, e.g.,
assert(i=1)
will never trigger the assert and will change the value of the variable i; it should
be coded as:
assert(i==1)
Uses Use the assert macro when you must make sure your assumption is accurate.
Example Check for a NULL pointer before using it.
void my_function (int * ptr){
assert(ptr);
...
}
6.3.11 Miscellaneous Debugging Tools
Noted here are a number of other debugging tools to consider.
General Debug Windows
In addition to the debug windows we have discussed already, there are three other windows that are avail-
able when a program is compiled: the Assembly, Register and Stack windows. They are described in detail
in Chapter 14, in the sections titled, Assembly (F10), Register Window and Stack (F12), respectively.