News for hackers. Stuff that matters.
Re:Depressing and faintly terrifying days for the C standard... by legulere on Wednesday May 30, 2018 @08:43PM (#17193125)
Signed integer overflow. It’s undefined because some platforms don’t use two’s complement.

Checking it after the fact is non-portable.

Re:Depressing and faintly terrifying days for the C standard... by rurban on Saturday June 02, 2018 @05:09AM (#17213643)
But not in sane compilers, they are better than the standard.

gcc, clang, icc all assume two's complement and happily overflow via -fwrapv. There's no such compiler on the Unisys anymore. They rather emulate two's complement. http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2218.htm

Re:Depressing and faintly terrifying days for the C standard... by AlexMax on Wednesday May 30, 2018 @09:49PM (#17193372)
Thankfully, not for very much longer...

http://wg21.link/P0907r2

C++, but apparently something similar is being considered for C as well.

https://twitter.com/jfbastien/status/989242576598327296?lang...

Re:Depressing and faintly terrifying days for the C standard... by JoeAltmaier on Wednesday May 30, 2018 @08:46PM (#17193136)
Isn't that mostly theoretical? I can't seem to find any processor that doesn't use 2's complement.
Re:Depressing and faintly terrifying days for the C standard... by gh02t on Wednesday May 30, 2018 @09:11PM (#17193224)
There are some old architectures that used one's complemeny and there are probably some still in service e.g.

https://en.m.wikipedia.org/wiki/UNIVAC_1100/2200_series

Re:Depressing and faintly terrifying days for the C standard... by davidgould on Thursday May 31, 2018 @06:20PM (#17200839)
I had the pleasure of programming on these. Having both positive and negative zeros is special and that they don't compare equal is extra special. And yet -- ones complement arithmetic is not even the oddest thing about Univac 1100s. I think the Univac corporate values statement must have included both "Dare to be different" and "Remember your past".
Re:Depressing and faintly terrifying days for the C standard... by JoeAltmaier on Thursday May 31, 2018 @09:27AM (#17196094)
Is anybody writing code for them? Probably not porting modern C anyway.

I assert this 'it might not be two's-complement' excuse is nonsense.

Re:Depressing and faintly terrifying days for the C standard... by gh02t on Thursday May 31, 2018 @10:51AM (#17196727)
I seriously doubt it.

I do agree with you, it's not a big deal for most devs. The only place I'd worry about it is systems where it might be expected to be in service for many years or intended to be ported frequently. In that case, you never know what sort of crazy architecture you may end up with in the future.

There's always something a bit icky with not sticking to the spec, but in the grand scheme of things relying on two's complement is not a big deal.

Re:Depressing and faintly terrifying days for the C standard... by rurban on Saturday June 02, 2018 @05:10AM (#17213649)
from the proposal http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2218.htm

"Nowadays Unisys emulates their old architecture using x86 CPUs with attached FPGAs for customers who have legacy applications which they’ve been unable to migrate. These applications are unlikely to be well served by modern C++, signed integers are the least of their problem. Post-modern C++ should focus on serving its existing users well, and incoming users should be blissfully unaware of integer esoterica."