How to get your code to compile

A long time ago... computers used relays instead of circuits. These relays would go up and down, and up and down, and generally create a lot of heat. So in the summer, the computer room would get quite hot and the programmers would have to leave the windows open. Insects would get in and plant themselves in the relays and get squished. After a while the computer would start having errors and the programmers would have to literally get in and de-bug the computer. We don't have relays anymore but somehow those bugs find a way in!


Before you Compile (The EMACS "window-screen")

Properly used, EMACS can screen out many potential bugs before they hit the compiler. The more bugs you catch before you actually compile the happier you will be.


Time to Compile (The G++ "bug-swatter")

Inevitably bugs will make it through your pre-compiler "screens" and rear their nasty heads. This is how they look when viewed under g++:
oddeven.C: In function `int main()':
oddeven.C:8: parse error before `>'
The first line tells you which function the error is in. In this case the error is in the main function main(). The second line has a number. This number is the line number that the error is occuring in. Finally, an often cryptic message follows trying to describe the nuisance.


What G++ says and what it means:

Notes:


Exercise 1:






After you Compile (The XXGDB Exterminator)

So you think you got all the bugs out? Wrong. You only got the weak ones the compiler could detect. The logic bugs and the dreaded Seg Fault bugs easily slip past the compiler "bug-swatter".

Now it's time to bring out the heavy guns. To use xxgdb, you must first compile with the -g option:

      g++ -g -o bugged bugged.C
Then issue the command:
      xxgdb bugged
Now you will see a window that is split in three sections, with the top half containing your source code, the middle half containing many buttons, and the bottom all this text garbage. Now go to the top half and click on a function that you want the program to stop at. In this case, we only have one function, main(). After you click on it, click on the "break" button in the middle section of xxgdb. Then press "run" and wait.

Soon a little red hand will appear with a blue arrow showing you that the program has run and now has stopped at the first point it could after the "break". Click on the "next" button and you will see the arrow move through your program. When you get to "cout", you will see the text appear on the bottom section of xxgdb. When you get to "cin", you will have to enter a number. Enter it in the bottom section of xxgdb.

Click on one of the variables, 'x'. Then click on the button, "display". You will see a tiny window appear on the bottom that says:

1: x = <The number you typed>

This will aid you immmensly in the future when you have big programs with loops and you want to keep track of your variables. In fact, if you are having problems with your first programming assignment, you will want to run xxgdb on it to see exactly what your loops are doing.

Now you should be able to step through the rest of the program by pressing "next".

Why doesn't the loop work?

Exercise 2:


(I didn't include any Segmentation Fault bugs in this. You'll find plenty of those yourself when you start using arrays and pointers)


<---- TAKE ME BACK TO CS1

John Escobar