Yes, this is well defined, it is basically adding max unsigned long long + 1
to -1
which will always be max unsigned long long
. This is covered in the draft C++ standard section 4.7
Integral conversions which says:
If the destination type is unsigned, the resulting value is the least unsigned integer congruent to the source integer (modulo 2n where n is the number of bits used to represent the unsigned type). [ Note: In a two’s complement representation, this conversion is conceptual and there is no change in the bit pattern (if there is no truncation). —end note ]
it does the same thing as C99 but the draft C99 standard is easier to understand, from section 6.3.1.3
Signed and unsigned integers:
Otherwise, if the new type is unsigned, the value is converted by repeatedly adding or subtracting one more than the maximum value that can be represented in the new type until the value is in the range of the new type.49)
where footnote 49
says:
The rules describe arithmetic on the mathematical value, not the value of a given type of expression.