Okay, Haloween is coming and I'm trying to get in the spirit of the thing. So I figured we could swap treats that are tricks. I've got a file tricks.h that I include at the bottom of my stdafx.h header file that I stuff with neat little programming tricks. The idea is that they are all one or just a few lines, no multipage functions. Anyhow, I figured I'd share my best and my easiest trick treats and see if anyone else will reciprocate. My best trick:
#ifdef TRACE
#undef TRACE
#define TRACE(s, ...) ATLTRACE((LPCSTR)(CStringA("%s(%d) : ")+s),__FILE__,__LINE__,__VA_ARGS__)
#endif
Now, I'm not one who's really fond of macros... Some programmers like to express the size of their manhood by how complicated and obfuscated their macros are. I'm not one of those coders. I only use a complicated macro when nothing else will get the job done as easily. Originally I had a full page function and a few macros that I replaced with this thing when Visual C++ got support for variadic macros. Anyhow what use is it? Well, when Visual C++ is compiling, it will spit out error messages into the debug window, something like this:
c:\programming\orgprintview.cpp(32) : error C2143: syntax error : missing ';' before '!'
When you hit F4 or doubleclick on that line, the IDE will deliver you to the file and line that generated the error. It turns out that if you format your TRACE statements to print "file(line) : message", then you can doubleclick in the output window on that line and the IDE will take you to that location. Pretty nifty. So those 4 lines when added to your tricks.h file will change all TRACE statements to do just that. Note that it only works on the char version of TRACE, not the wchar or tchar. that's all I use though so it's fine by me. My simplest tricks.h entry is this:
#define IDENTICAL 0 // use: if(IDENTICAL==strcmp(a,b)) {;}
And the comment shows it's usage... I try as hard as possible to have my code read like english (so long as it doesnt get more complicated), and this easy macro helps a bit :) Anyhow, Happy Haloween, and hit me back with something to add to my tricks.h Dan K (p.s. I'm looking for a good paying job anywhere in the US, or abroad actually, hook me up :))
modified on Monday, October 12, 2009 8:32 PM