On 11/24/18 7:52 AM, Peter Dimov via Boost wrote:
Daniela Engert wrote:
Making it an error would be a useful first step towards making it work correctly. :-)
(It's perfectly possible to compare a value in [INT_MIN, INT_MAX] with a value in [0, UINT_MAX], it's just that the standard says op< needs to do the wrong thing.)
I appologize in advance for perhaps hijacking the thread, but I can't restrain myself from the opportunity to plug the most recent addition to the boost libaries - safe_numerics. C/C++ "arithmetic" is not really arithmetic. That is, results of the arithmetic operations are not guaranteed to map to their counterparts in the arithmetic of integers. The C/C++ rules for promoting operands to the same type can and do introduce errors. Then the application of operations defined in terms to unbounded integers to the bounded integers we use in our programs can and do return incorrect results. Warnings like the above can definitely help, but can't guarantee that the problem does not occur. It is not possible to prove that these problems cannot occur by visual inspection. We're living a lie. So I invite all parties who write programs which much function as written to take a look a the boost safe numerics library. I think you'll find it interesting. Robert Ramey