Using CodeBlocks 10.05 – Part 3

As previously mentioned, C++ All-In-One Desk Reference For Dummies is currently designed around CodeBlocks 8.02. However, a number of readers have written to ask about the latest version of CodeBlocks, 10.05. I introduced this new version in Using CodeBlocks 10.05 – Part 1, where I discussed the general look of the new version. Since that time, I’ve tried out more of the book’s source code with this new version and still haven’t encountered any problems except the one described in Using CodeBlocks 10.05 – Part 2 on my test systems. Of course, that doesn’t mean the new version will run flawlessly on your system, so I’m still looking for input from readers about it.

Today’s post focuses on the debugger, which has changed a bit since the CodeBlocks 8.02 release. Book III, starting on page 349, discusses errors in programming. Chapter 2, page 361, discusses debugging techniques. Figure 2-1 shows the Debugging toolbar with callouts for each button. There isn’t any difference in this toolbar for CodeBlocks 10.05. You can also press F8 to start the debugger, just as in previous versions.

This post works with the example found in the \Author\BookIII\Chapter02\BuggyProgram folder of the source code. There is actually a small error in the example code supplied with the book in that example. Look at the following line of code:

// system("PAUSE”); // add this for Windows

There is an odd looking double quote after the word PAUSE. If you uncomment this line so the code pauses, the compiler will register a warning: missing terminating ” character error. Make sure you change that odd looking double quote to an actual double quote when you run the code. The resulting change should look like this:

system("PAUSE"); // add this for Windows

when you remove the comment.

Page 363 tells you about breakpoints. To use the sample, you set a breakpoint at line 22. If you want, you can click on the left side, as described in the book. You also have the option of right clicking on the line number to display a context menu that contains options for setting or removing a breakpoint. Here’s how the context menu appears when you want to set a breakpoint.

CodeBlocks10_05Part2_1

Simply choose Add Breakpoint to set the breakpoint on that line. If a breakpoint is already on the line, you’ll see these options instead.

CodeBlocks10_05Part2_2

To clear a breakpoint, simply choose the Remove Breakpoint option. It’s also possible to change how a breakpoint works. Click Edit Breakpoint and you’ll see the Edit Breakpoint dialog box shown here.

CodeBlocks10_05Part2_3

If you clear the Enabled checkbox, the IDE retains the breakpoint, but ignores it during debugging. The breakpoint appearance doesn’t change (many IDEs display the breakpoint as a hollow circle when the breakpoint is disabled). This means that you must actually check the breakpoint status before you assume something has gone wrong.

It’s also possible to set conditional breakpoints. For example, if you’re working in a loop, you can tell the IDE to ignore the breakpoint until the loop has executed a certain number of times by checking the Ignore Count Before Break option and setting the number of times the IDE should ignore the breakpoint before it actually stops.

As an alternative, you can set a condition the code must meet before the breakpoint executes. For example, you might set a breakpoint that says result = 15. If result is any other value, the IDE ignores the breakpoint. In order to use this kind of conditional breakpoint, you check the Break When Expression Is True option and enter the expression you want to check.

If you have some extremely odd condition to check, you can combine both conditional features. The breakpoint seems to work only if both conditions are true. In other words, you can’t check for one condition or the other, but must instead look for both conditions. If someone has a different experience with this feature, please be sure to let me know.

I tried the debugging steps in Chapter 2 and didn’t encounter any issues. I encourage you to try the various conditional breakpoint features as you work through other examples in the book, especially examples that employ looping. If you find any debugging features that fail to work, please be sure to let me know at John@JohnMuellerBooks.com.

 

Author: John

John Mueller is a freelance author and technical editor. He has writing in his blood, having produced 99 books and over 600 articles to date. The topics range from networking to artificial intelligence and from database management to heads-down programming. Some of his current books include a Web security book, discussions of how to manage big data using data science, a Windows command -line reference, and a book that shows how to build your own custom PC. His technical editing skills have helped over more than 67 authors refine the content of their manuscripts. John has provided technical editing services to both Data Based Advisor and Coast Compute magazines. He has also contributed articles to magazines such as Software Quality Connection, DevSource, InformIT, SQL Server Professional, Visual C++ Developer, Hard Core Visual Basic, asp.netPRO, Software Test and Performance, and Visual Basic Developer. Be sure to read John’s blog at http://blog.johnmuellerbooks.com/. When John isn’t working at the computer, you can find him outside in the garden, cutting wood, or generally enjoying nature. John also likes making wine and knitting. When not occupied with anything else, he makes glycerin soap and candles, which comes in handy for gift baskets. You can reach John on the Internet at John@JohnMuellerBooks.com. John is also setting up a website at http://www.johnmuellerbooks.com/. Feel free to take a look and make suggestions on how he can improve it.