R
Raymond
Source:
http://moryton.blogspot.com/2007/08/detecting-overflowunderflow-when.html
Example from source:
char unsigned augend (255);
char unsigned const addend (255);
char unsigned const sum (augend + addend);
if (sum < augend)
{
std:uts ("Overflowed!");
}
sum = augend + addend
sum = 255 + 255
sum = 510 modulo 256 // Behind the scenes.
sum = 254
Does it touch any implementation defined or undefined behaviour, or was
that specific to signed integers (on some platforms)?
What other methods are there for detecting unsigned integer overflow
and/or underflow in C++?
http://moryton.blogspot.com/2007/08/detecting-overflowunderflow-when.html
Example from source:
char unsigned augend (255);
char unsigned const addend (255);
char unsigned const sum (augend + addend);
if (sum < augend)
{
std:uts ("Overflowed!");
}
sum = augend + addend
sum = 255 + 255
sum = 510 modulo 256 // Behind the scenes.
sum = 254
Does it touch any implementation defined or undefined behaviour, or was
that specific to signed integers (on some platforms)?
What other methods are there for detecting unsigned integer overflow
and/or underflow in C++?