News for hackers. Stuff that matters.
Re:In C++, is empty() faster than comparing the size with zero? by IshKebab on Thursday October 28, 2021 @03:17PM (#29030360)
> To make it clearer, you could imagine an alternate version of C that aborted the program if an integer overflowed. Then there would be no undefined behavior at all - but the optimization is still possible.

The optimisation wouldn't be possible in that case because then the program wouldn't abort when the integer overflowed. It would break the defined behaviour that overflow=abort.

Re:In C++, is empty() faster than comparing the size with zero? by caf on Thursday October 28, 2021 @07:08PM (#29033227)
This is correct. In the motivating example, it would have to scan the entire list of pointers to see whether it finds a NULL link before it overflows the size counter or not.
Re:In C++, is empty() faster than comparing the size with zero? by joosters on Friday October 29, 2021 @05:21AM (#29036749)
Ah, you're completely right, the compiler couldn't hid or assume away the aborts as they would now be part of the spec.