Using enum Types in C

Chapter 3 - Writing, Compiling, and Debugging Simple Programs

Visual C++ 6: The Complete Reference
Chris H. Pappas and William H. Murray, III
  Copyright 1998 The McGraw-Hill Companies

Advanced Debugging Techniques
You can think of a breakpoint as a stop sign for the integrated debugger. Logically, breakpoints tell the debugger that all statements prior to the breakpoint are OK, so the debugger shouldn’t waste time single-stepping through them.
The easiest way to set a breakpoint is to click on the breakpoint control, which you can do if the toolbar is visible. This button is the second from the right on the toolbar. The picture on it resembles a hand signaling “stop.”
The Breakpoint button is a toggle. If the line that the cursor is on when you click on the button does not contain a breakpoint, the command sets one. If the line that the cursor is on already has a breakpoint set, the command removes it. You can set as many breakpoints as you need by repeating this sequence. The Go command, when selected, will always run your program from the current line up to the next break point.
For the sample program, you know that all statements prior to the scanf( ) function call are OK. You have just edited this line and are now interested in seeing if the new statement works properly. For the sake of efficient debugging, you are going to set a break point on line 26, at the scanf( ) function.
Figure 3-20 illustrates another approach to setting breakpoints: using the Edit | Breakpoints... command.
Figure 3-20: Setting breakpoints
This menu item opens up the Breakpoints dialog box. The default breakpoint type is Break at Location. All you need to do is type in the line number in the Location: box. For our example, this is line 20. (If your scanf( ) statement is on a different line number, possibly because there are extra blank lines in the source code, enter your source file’s line number for the scanf( ) statement.) Now choose the OK button.
Using Breakpoints
To debug a program at full speed up to, but not including, the breakpoint, you can use the Debug | Go menu item, as shown in Figure 3-21.
Figure 3-21: Running a program at full speed with breakpoints
Assuming that you have the previously described breakpoint set, invoke the Go command. (Either select the command with the mouse, use the keyboard to access the command via the menus, or press f5.) Notice that the trace arrow speeds quickly to the statement containing the scanf( ) function call and then stops.
Once the debugger stops at a breakpoint, you can return to single-stepping through the program or even pause to examine a variable’s contents. For now, we are interested in seeing if the syntax change made to the scanf( ) statement works. Choose the Step Over option, switch to the program’s execution window, type an uppercase Y, and press enter. (You want Step Over so the debugger doesn’t attempt to step into the scanf( ) function. Stepping in will prompt for location of the SCANF.C file. If you Cancel this, then you’re in disassembly and the window won’t be ready to accept input, etc.)
Success! The integrated debugger no longer flags you with warning message windows. However, does this really mean that the code problem is fixed? The simplest way to answer this question is to examine the current contents of the variable continu.
An Introduction to QuickWatch
The QuickWatch... command opens up the QuickWatch dialog box, which allows you to instantaneously view and modify the contents of a variable. The fastest way to put a variable in the QuickWatch window is to place the cursor on the variable in your source code and press shift-f9. If you do this with the sample program, you will see a QuickWatch dialog box similar to the one in Figure 3-22.
Figure 3-22: A QuickWatch window
Now that you know that the contents of continu are correct, you can run the program at full speed to the end, using the Debug | Go command, as shown in Figure 3-23.
Figure 3-23: Viewing a variable’s contents within the source file

Books24x7.com, Inc 2000 –  


Visual C++ 6(c) The Complete Reference
Visual Studio 6: The Complete Reference
ISBN: B00007FYGA
EAN: N/A
Year: 1998
Pages: 207

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net