Let the Language Help! Use enum instead of int enum color {black, white, red}; // avoids bad values Use const instead of #define const uint64_t x = 1; // helps with type checking uint64_t y = x << 40; // avoids 32-bit overflow bug Use inline instead of #define If it’s too big to inline, the call overhead doesn’t matter Many compilers inline automatically even without keyword
Use typedef with static analysis
typedef uint32_t feet; typedef uint32_t meters; feet x = 15; meters y = x; // feet to meters assignment error https://goo.gl/6SqG2i