Write Programs for
Debugging
You can make your programs easier to debug by following these
simple guidelines:
- Do not hand-tune your source code
for performance until you have fully debugged and tested
the untuned version. Hand tuning may introduce new bugs
or make the logic of your code harder to understand.
- Where possible, do not put multiple statements on a
single line, because some debugger features operate on a
line basis. For
example, you cannot step over or
set line breakpoints on more than one statement
on the same line.
- Assign intermediate expression
values to temporary variables to make it easier to verify
intermediate results. For example, you
will not be able to display the substrings of IString
objects in the first C++ code fragment below, but you
will in the second:
// Can't see the substrings in this one
if (StrA.subString(x,y)==StrB.subString(m,n)) dups++;
// Can see the substrings here
IString SubA=StrA.subString(x,y);
IString SubB=StrB.subString(m,n)
if (SubA==SubB) dups++;
To be able to debug your
programs at the level of source code statements, you must specify
C++ compiler options that generate debug information, and in
some cases you must specify options that enable the debugger to
work properly with your code.

C++ Compiler Options