3 ms·
Using "unsigned ints" for values that will never be negative allows you to perform one validation test instead of two. Use a typedef to avoid writing "unsigned"
by nanex 14y ago
Using "unsigned ints" for values that will never be negative allows you to perform one validation test instead of two. Use a typedef to avoid writing "unsigned" everywhere and you end up with less clutter in the code (for humans) and in the binary (for machines).
nanex
- ajuc 14y agoYou should check before the operation that can produce result outside the valid range anyway. Wrong example: unsigned int z = x - y; if (z > BIG_NUMBER) { return false; } Good example: if (y > x) { return false; } unsigned int z = x - y;