X Macros
No problem can be solved at the same level of thinking that created it.1 — “Albert Einstein” Consistency Challenge The first time I ran into X Macros was while debugging an out-of-bounds access issue. Here is a simplified example: // a.h typedef enum { SYS_OK, SYS_ERR_TIMEOUT, SYS_ERR_BUSY, SYS_ERR_INVALID_ARG, SYS_ERR_NOT_FOUND } SysState; // a.c const char *state_desc[] = { [SYS_OK] = "System OK", [SYS_ERR_TIMEOUT] = "Timeout", [SYS_ERR_BUSY] = "System Busy", [SYS_ERR_INVALID_ARG] = "Invalid Argument" // SYS_ERR_NOT_FOUND is missing here }; int main() { printf("State = %s\n", state_desc[SYS_ERR_NOT_FOUND]); } The issue is easy to spot: SYS_ERR_NOT_FOUND was added to the enum, but the string table was not updated. ...