January 23, 2011
The tried-and-true C way to determine the length of an array is this: #define sizeof_array(x) (sizeof(x) / sizeof(x[0])) As H. L. Mencken put it, “there is always a well-known solution to every human problem — neat, plausible, and wrong.” That is certainly the case with this approach. It’s short, to the point, very easy to [...]
March 1, 2009
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 [...]
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 [...]