
144 Chapter 10: Optimizing Your Code
lines of the high-level language program might have been removed from the pro-
gram altogether (as they were in the previous example)! As a result, you might be
unable to set a breakpoint on a particular line of the program or examine the
value of a variable of interest.
Once you’ve got the automatic optimizations working, here are some tips for fur-
ther reducing the size of your code by hand:
Avoid standard library routines
One of the best things you can do to reduce the size of your program is to
avoid using large standard library routines. Many of the largest are expensive
only because they try to handle all possible cases. It might be possible to
implement a subset of the functionality yourself with significantly less code.
For example, the standard C library’s sprintf routine is notoriously large. Much
of this bulk is located within the floating-point manipulation routines on
which it depends. But if you don’t need to format and display floating-point
values (%f or %g), you could write your own integer-only version of sprintf
and save several kilobytes of code space. In fact, a few implementations of the
standard C library (Cygnus’ newlib comes to mind) include just such a func-
tion, called siprintf.
Native word size
Every processor has a native word size, and the ANSI C and C++ standards
state that data type int must always map to that size. Manipulation ...