A
Andrew Koenig
Is unsigned overflow defined in all cases? Where in the C++ standard does
it
say that?
Subclause 3.9.1, paragraph 4:
Unsigned integers, declared unsigned, shall obey the laws of arithmetic
modulo 2^n where n is the number of bits in the value representation of that
particular size of integer. [Footnote: This implies that unsigned arithmetic
does not overflow because a result that cannot be represented by the
resulting unsigned integer type is reduced modulo the number that is one
greater than the largest value that can be represented by the resulting
unsigned integer type.]
The situation with signed overflow is ridiculous. The standard should say
overflow is defined as if twos complement arithmetic was being performed.
Why? That would prohibit implementations from treating integer overflow as
an error.