>>64785530>unsigned a, b;>unsigned long long o;>o = a + b;
calls operator+(unsigned, unsigned) -> unsigned
then calls static_cast<unsigned long long>(unsigned) to convert the temporary for assignment>causing o contain unknown value depends on the overflow logic of the machine>unknown
No, the C/C++ standard mandates ~unsigned~ overflow is always modulo 256^sizeof(type).
See §6.2.5/9>A computation involving unsigned operands can never overﬂow, 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 type.>http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf>is it okay to assume that integer calculation doesn't have any maximum limit
No.>o = (a * b) & 0xffffffffffffffff;
The AND is redundant.>p = (a * b) % (0xffffffffffffffff + 1);
0xffffffffffffffff + 1 overflows to 0 and %0 is undefined behavior.