Dec 4, 2013

[C++][NOTE][BIGINNER] signed int overflow

Reference:
Signed Overflow
why-does-integer-overflow-on-x86-with-gcc-cause-an-infinite-loop
Signed integer overflow is undefined behaviour according to the standard §5.4:


"If during the evaluation of an expression, the result is not mathematically

defined or not in the range of representable values for its type, the behavior is undefined."

Most implementations will just wrap around, so if you try it out on your machine,

you will probably see the same as if you had done

std::cout << std::numeric_limits<int>::min();
Relying on such undefined behaviour is however _not_ safe.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.