Re:C and C++ Prioritize Performance over Correctness
by kragen on Friday August 18, 2023 @02:15PM
(#37179840)
like x > 2147483547u in this case?
[ Parent
| on HN ]
Re:C and C++ Prioritize Performance over Correctness
by gavinhoward on Friday August 18, 2023 @02:42PM
(#37180212)
Correct. It will still overflow, but it's not UB and won't be optimized away.
Re:C and C++ Prioritize Performance over Correctness
by kragen on Friday August 18, 2023 @03:04PM
(#37180526)
by 'overflow' do you mean 'set the high bit'
Re:C and C++ Prioritize Performance over Correctness
by gavinhoward on Friday August 18, 2023 @03:17PM
(#37180696)
Correct.
I have routines that take the unsigned values and interpret them as signed, two's-complement values.
So you would write this:
val = temp1 + temp2;
if (y_ssize_lt(val, temp1)) y_trap();
That `y_ssize_lt()` function computes whether `val` is less than `temp1` as though they were signed, two's-complement integers. But because they are actually unsigned, the compiler cannot be malicious and delete that code.
Re:C and C++ Prioritize Performance over Correctness
by kragen on Friday August 18, 2023 @03:55PM
(#37181226)
i see, thanks
maybe we should develop a nonmalicious compiler
Re:C and C++ Prioritize Performance over Correctness
by gavinhoward on Friday August 18, 2023 @09:41PM
(#37184593)