Integer arithmetics in C# can be set to throw an OverflowException using checked
, as in the following example:
int a = foo();
int b = bar()
int result = checked(a * b); // Will result in OverflowException if this overflows
I'm currently getting more into C programming and just found a bug that was due to an integer overflow - which would have been much more easier to find with something like checked
- and I ask myself: Why is nothing similar implemented in C? Can someone explain it to me or point me out (some standard reference, etc.) where it is stated why such a construct is not part of the C language?
Or am I completely wrong and there is some built-in functionality to check for (integer) overflows on arithmetic operations?