[Courses] [C] Beginner's Lesson 14: Debugging and Optimization

KWMelvin kwmelvin at intrex.net
Sun Dec 8 15:21:08 EST 2002


Lesson 14 is: Debugging and Optimization. Since my copy of _PCP_
was published in 1991, a lot has changed, so I'm not going to
send out a copy of Chapter 14.  Instead, the assignment is to
work through Peter's gdb Tutorial.  I have gdb-tut.tgz on my
site. You may want to copy index.html to gdb.html so it all
works as linked. I found that glitch after I uploaded it. All
the other gdb?.html files are properly named.

As far as a beginner optimizing a C program: I think the compiler
can do a much better job than we ever could.  Use the -O compiler
option on the command-line to optimize your program:  

    $ gcc testme.c -o testme -O -Wall -ansi -pedantic
                              |_____ optimize option

If you use the gdb debugger option (-g) it is a good idea not to
use the -O (optimize) option.  You can always recompile with -O
after the program is debugged.

I'm hoping that the more experienced C programmers can add to this.
For those who use ddd: I think it will be helpful to work through
the gdb tutorial.  I understand that ddd is a GUI frontend to gdb,
so it might be a good idea to understand what is going on in the
background?  We've already covered using stratigically placed printf()
functions in a program for debugging. 

Happy Programming!

More information about the Courses mailing list