CS 117 Labs, Fall 2000
September 13, 2000
Each of these
programs contains instructions for you. To get started, click
on the name of the first program (hello.cpp), copy and paste the program
into a gEdit window, and save the resulting file as hello.cpp in your
own account. Then read the instructions at the top of hello.cpp
and do what they tell you to do. Repeat for the rest of the
files listed below.
If you don't finish during this class period, do so later.
Have fun.
This process of "get the file and follow the instructions and
try to answer the questions" is how we will do things on the
three or four occasions we have class in lab.
I usually try to have plenty of stuff for
everyone to do during a 70 minute period, so you may not be able
to get through everything during class. If you haven't finished
all the lab exercises, come back and finish them up later. The
material in these labs is important, so the
exercises will stay accessible on the Web all term.
September 25, 2000
October 4, 2000
I. The ddd debugger
Your goal here is to get to know ddd, a "debugger" program
that can help you find the problems with your programs. Debuggers
can't help you until your program compiles, but once you have
eliminated all compiler errors, a debugger can be one of your most
valuable tools.
Today, you'll use ddd to (1) watch a variable, (2) single-step
through a program, and (3) set breakpoints. All three of these
operations should become clear shortly.
- To use ddd in the first place, you first have to do a weird
thing. Use gEdit to open a file called .cshrc.linux that you
will find in your account. Don't change anything that is already
there, but add the following line to the end of the file:
setenv LD_LIBRARY_PATH "/usr/local/lib:/usr/lib"
Save and then close the file. Finally, close any terminal windows
you have open and open a new one. You should be ready to go.
- Save the program odds.cpp
in your account, and compile it using the usual command:
g++ -g -Wall -o odds odds.cpp
- Run the command
ddd odds
- Open the data display. Select Data Window from the
View menu. A grid should appear at the top of the ddd
window.
- Setting a breakpoint. Click in the source code part of
the ddd window at the beginning of the line where N is
declared. Then click on the "Breakpoint" button. A small
stop sign should appear in the source code.
- Running the program. Click "Run" in the little palette
window. The program will run until your breakpoint and stop
there.
- Watching a variable.
Double-click on N. A small window with N's name and
value will appear in the Data grid. Move it to a convenient
spot. You can watch sum, too.
- Single stepping. The single-stepping feature of ddd allows
you to watch how your variables evolve while the program executes
one instruction at a time. Click on the "Step" button in
the palette. Keep doing so until you step into the
SumOfOdds function. Once you're there, double-click on N,
odd, and sum to watch those three variables evolve.
Keep stepping.
II. Compiler error scavenger hunt
For this part of the lab, your goal as a class is to find as many
different compiler error messages as possible, and list
them along with their causes.
Start with one of the programs you have written, one of the lab
exercise programs listed above, or one of the
example programs
from class. Introduce a small error into it. Remove
a semi-colon, add an extra brace (try { one time, } the next),
delete a return statement, or whatever. Try to compile the
program. Write down the error you introduced, and the first
error message the compiler generated. We'll make a master
list on the white board.
Be creative. There are lots of ways to confuse a compiler
with a tiny mistake.
Jeff Ondich,
Department of Mathematics and Computer Science,
Carleton College, Northfield, MN
55057,
(507) 646-4364,
jondich@carleton.edu