News for hackers. Stuff that matters.
Re:Undefined behavior is often a thing for C programmers (2011) by barrkel on Thursday September 03, 2020 @10:32AM (#24364450)
One of the more pernicious problems is security checks written to detect underhanded violations of constraints being eliminated because the compiler doesn't recognize the underhandedness is possible.

In a past life, I depended on signed overflow to detect out of bounds memory allocations. That kind of stuff gets compiled away these days, you need to be cleverer to detect when the user is deliberately trying to invoke UB. And because the compiler doesn't believe in UB, there's the risk it's going to remove your detection logic.

Re:Undefined behavior is often a thing for C programmers (2011) by sharpneli on Thursday September 03, 2020 @10:40AM (#24364508)
Making signed overflow to be well defined would be so much better.

IIRC C++ just decided that signed numbers are two's complement and that's that. C could really use similar thing.

Re:Undefined behavior is often a thing for C programmers (2011) by steerablesafe on Thursday September 03, 2020 @10:44AM (#24364533)
> IIRC C++ just decided that signed numbers are two's complement and that's that.

Signed integer overflow is still undefined in C++.

Re:Undefined behavior is often a thing for C programmers (2011) by sharpneli on Thursday September 03, 2020 @12:05PM (#24365451)
You are correct. I misremembered, it was just a proposal that was not taken into the spec.
Re:Undefined behavior is often a thing for C programmers (2011) by steerablesafe on Thursday September 03, 2020 @12:30PM (#24365723)
No, it's taken into the spec. It affects unsigned <-> signed conversions and maybe other things. Not integer overflow though.
Re:Undefined behavior is often a thing for C programmers (2011) by sharpneli on Thursday September 03, 2020 @04:43PM (#24368673)
Ah. Makes sense as that’s relatively cheap to emulate by just doing conversion when loading and storing from memory, but allows the use of HW even in case of ones complement implementation.