The Daily WTF
Andrea writes to confess some sins, though I’m not sure who the real sinner is. To understand the sins, we have to talk a little bit about C/C++ macros.
Andrea was working on some software to control a dot-matrix display from an embedded device. Send an array of bytes to it, and the correct bits on the display light up. Now, if you’re building something like this, you want an easy way to “remember” the proper sequences. So you might want to do something like:
uint8_t glyph0[] = {‘0’, 0x0E, 0x11, 0x0E, 0}; uint8_t glyph1[] = {‘1’, 0x09, 0x1F, 0x01, 0};
And so on. And heck, you might want to go so far as to have a lookup array, so you might have a const uint8_t *const glyphs[] = {glyph0, glyph1…}. Now, you could just hardcode those definitions, but wouldn’t it be cool to use macros to
To read the full article click on the 'post' link at the top.