11.07.2015 Views

tYSR20

tYSR20

tYSR20

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 10: Debugging C++ 151You can now select Next Step either from the Debug menu, from the debugtoolbar, or by pressing F7 to execute one line at a time in the program. Theblue marking moves to the next executable statement, skipping over bothdeclarations. (A declaration is not a command and is not executed. A declarationsimply allocates space for a variable.) Executing a single C++ statementis also known as single stepping. You can switch to the Console window to seethat the single output statement has executed, as shown in Figure 10-3.Figure 10-3:You canclick theConsolewindow atany time tosee anyprogramoutput.Execute the Next Step two more times to move the point of execution to thecall to StringEmUp(). So far, so good. When you select Next Step one moretime, however, the program crashes ignominiously just as before. You nowknow that the problem is encountered somewhere within the StringEmUp()function.When the program crashes within a function, either the function contains abug, or the arguments passed to the function are incorrect.The Next Step command treats a function call like a single command. This isknown as stepping over the function. However, a function consists of a numberof C++ statements of its own. You need to execute each of the statementswithin the function in order to better see what’s going on. I need a differenttype of single step command, one that steps into the function. This functionalityis provided by the Step Into debugger command.Restart the program by selecting the Program Reset menu item from theDebug menu, by clicking on Stop Execution from the debug toolbar, or bypressing Alt+F2. This time, you want to save a little time executing right up tofunction call before stopping. Click the existing red circle to toggle the existingbreakpoint off. The dot disappears. Next click in the trough across fromthe call to the function to set a new breakpoint, as shown in Figure 10-4.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!