Your examples B is a bend constant at compile time, indicating to the compiler that it guarantees overflow.
Since your examples use variables, expressions cannot be (completely) added at a constant speed, so the compiler cannot guarantee that the values ββwill lead to overflow.
For example...
int val = 0; // some other thread changes `val` to -5... val = val + Int32.MaxValue +2; // no overflow
However, if you know that val will not change and assign 0:
const int startval = 0; int val = startval + Int32.MaxValue + 2;
You can get a compile-time overflow check because the value can be fully determined and therefore permanently added.
Mark rushakoff
source share