3 ms·
Adding "assuming the compiler is not insane and uses -fwrap" would be a bit cumbersome. The fact remains that the checks looks correct to anyone familiar with
by loup-vaillant 8y ago
Adding "assuming the compiler is not insane and uses -fwrap" would be a bit cumbersome.
The fact remains that the checks looks correct to anyone familiar with 2's complement, yet unfamiliar with the intricacies of the C and C++ standard, which are not low level, contrary to what they were being told at school.
The resistance of the committee about this very issue, as shown by revision 2 of this proposal¹, is enough to make me hope C and C++ will go the way of COBOL.
That said, 2's complement guarantees that converting everything to unsigned before performing an operation, then converting back afterwards, is guaranteed to produce the same results as -fwrap (except for division and modulo). Source to source transformation tools may help us bypass undefined behaviour without resorting to non-standard compiler flags, or implementation defined behaviour.
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0907r2.html http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p090...