Numbers are infinite, but the types that hold them are not. Each numeric type has hard upper and lower bounds. Try to calculate or assign numbers
beyond those bounds, and the result will be surprising:
- For unsigned types, it will be a value that has silently wrapped around from the expected positive value to another one, following the rules of
modular arithmetic (if the maximum
unsigned char
is 255, adding 10 to an unsigned char
equals to 250 will yield the value
4)
- For signed type, this is undefined behavior.
Noncompliant code example
void test(char c) {
switch (c) {
case 2000: // Noncompliant
// ...
break;
}
int a = 4608 * 1024 * 1024; // Noncompliant
}