| You are here: | About>Computing & Technology>C / C++ / C#> Tools and Utilities> How to Debug Windows C & C++ Applications Without a Debugger |
![]() | C / C++ / C# |
![]() Elsewhere on the WebHow to Debug Windows Applications Without a DebuggerFixing Part-Time Bugs in C & C++One of the harder classes of bugs to find is that which occurs in release code but not debug. I call this a part-time bug. It's often an uninitialized variable to blame. One way to debug this is to build into your application calls to OutputDebugString. In Win 32 this is declared in the Windows.h include file. The somewhat contrived example below shows this. In reality of course the compiler issues warnings and you should never ignore compiler warnings! OutputDebugString() expects a const char * which is easy enough in C. In C++, though a little finagling is required and that is what the function DbgOutInt() does. It takes a string label and an int variable, uses a stringstream to do an int to string conversion, then uses the string member function c_str(c) to provide access to a C type string and that is what OutputDebugString() requires.
#include "stdafx.h" // Only for Microsoft compilers The obvious bug here is that the variable a is never initialized and seeing the debug output Value of b= -858993459is a big clue! Viewing Debug OutputIf you run this inside a debugger, you should see the output text in an output window. Both Borland and Microsoft IDEs have this.From the command line you require a utility to capture the debug output. The SysInternals.com DebugView UtilityThe sysinternals.com website (recently relocated to Microsoft who bought them, but the link still works) provides an excellent utility called DebugView. You'll find it listed on the Miscellaneous Utilities page and it's a quick download.Just run this and click the help for instructions. You can stop and start logging at any time and save the captured output to disk as a text file. Elsewhere on the Web |
Las Vegas on a BudgetFind a BargainHotel DealsCheap EatsFree AttractionsEntertainment for Less |
All Topics | Email Article | | | ![]() |
| Advertising Info | News & Events | Work at About | SiteMap | Reprints | Help | Our Story | Be a Guide |
| User Agreement | Ethics Policy | Patent Info. | Privacy Policy | ©2008 About, Inc., A part of The New York Times Company. All rights reserved. |



