News for hackers. Stuff that matters.
Re:C meeting is over. C23 added: by MaxBarraclough on Saturday February 19, 2022 @07:00AM (#30396464)
Perhaps I'm missing something obvious, but isn't that orthogonal to representation? You could implement saturating arithmetic for any representation scheme, no?
Re:C meeting is over. C23 added: by tomsmeding on Saturday February 19, 2022 @09:14AM (#30397260)
You can only observe whether the representation is 2s-complement or not if you can see what wrapping does.
Re:C meeting is over. C23 added: by MaxBarraclough on Saturday February 19, 2022 @09:25AM (#30397340)
That doesn't sound right. You can use the union trick in C (but not C++, strictly speaking) to read the bit-pattern of a signed integer as an unsigned integer, for example. [0]

Overflow of signed integer types remains undefined behaviour in both C and C++. A compiler is free to make a promise like signed integer overflow is always handled with wrapping or signed integer overflow is always handled with saturation. (GCC has a flag, -fwrapv, to enable guaranteed wrapping. [1])

[0] https://stackoverflow.com/a/25664954/

[1] https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html