caustik's blog

programming and music

Archive for October, 2006

Painless Debug Console

with 18 comments

I have had the pleasure of writing a pretty large number of apps for Windows. There are a few things that I have learned, over time, that have really helped to improve my productivity. One of those things is a basic debug console.

Typically, a debug console is handy – go figure – while you’re debugging. Once you have a release quality build, you won’t want the debug console hanging around anymore.

This is one of those snippets of code that, while brutally simple, is rather non-obvious and most people don’t know of.

#ifdef MYAPP_DEBUG_TRACE
if(AllocConsole())
{
    freopen("CONOUT$", "wt", stdout);

    SetConsoleTitle(L"MyApp : Debug Console");

    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED);

    printf("\n");
    printf(" MyApp Debug Console\n");
    printf("\n");
}
#endif

Basically this code, if debug trace preprocessor is set (add MYAPP_DEBUG_TRACE to your preprocessor settings), will allocate a nice little debug console window, change the title, set the font colors, and redirect standard output to the console.

This snippet of code can be added to any Win32 application, and gives you the instant capability to spit out oodles of delicious debugging data. Typically, I combine this method with something along these lines:

#ifdef __cplusplus
inline void null_func(char *format, ...) { }
#define DbgEmpty null_func
#else
#define DbgEmpty { }
#endif
/* Debug Trace Enabled */
#ifdef  MYAPP_DEBUG_TRACE
#include
#define DbgPrintf printf
#else
/* Debug Trace Disabled */
#define DbgPrintf DbgEmpty
#endif

Now, you can use the function “DbgPrintf” just as if it was “printf” – and it will compile away to nothing in a release mode build!

Written by caustik

October 24th, 2006 at 5:51 am

Posted in Programming

Tagged with

Bacon McFlurry

with 7 comments

McDonalds officially unveiled yet another new flavor of McFlurry this weekend. The latest addition to the McDonalds menu combines the popular McFlurry dessert with the salted and smoked meat from the back and sides of a pig.

Executive Vice President Claire Babrowski says “We were just looking for something new. We wanted to combine dessert and breakfast, and I think we accomplished that.”

mcflurry

Written by caustik

October 14th, 2006 at 8:45 pm

Posted in Funny

Tagged with , ,