Stupid C++ Tricks: do/while(0) and C4127

March 1, 2009
Tags: , , , ,

A nice little quickie:  I briefly discuss in my assert ramblings why it’s important to wrap all of your multi-line macros in do/while(0) blocks.  An unfortunate side-effect of this is that the construction // NOISY CODE #define MULTI_LINE_MACRO \ do { \ std::printf(“Hello “); \ std::printf(“world!\n”); \ } while (0) will trigger C4127: “Conditional expression […]

20

Stupid C++ Tricks: Adventures in Assert

February 10, 2009

This is a re-hosting of the original Assert article I wrote in April 2007,  during the epic rise and fall of Power of Two Games.  I’m reprinting it here on my personal site now that Pow2 is defunct and expired. Of the few reasons we failed, the lack of a good assert macro was not […]

20