News for hackers. Stuff that matters.
Re:A Quiz About Integers in C by matheusalmeida on Sunday June 03, 2012 @07:37PM (#4062046)
That is true but it's not the reason... INT_MAX + 1 must be 0 for unsigned int because the C standard defines wrap-around behavior for unsigned data types. Saturated data types are only defined in Embedded C. E.g.: Sat Fract
Re:A Quiz About Integers in C by jacquesgt on Sunday June 03, 2012 @09:29PM (#4062287)
That is the entire reason. Because the representation of signed numbers could vary from implementation to implementation, making INT_MAX + 1 (or any signed integer overflow) undefined allows for more efficient generated code. If it were defined in some way, the generated code would need checks for overflow wherever it was possible, which would lead to bigger and slower code.

INT_MAX + 1 is never 0 for unsigned int. (unsigned)INT_MAX + 1 is equal to INT_MAX + 1. You're thinking of UINT_MAX + 1, which is always 0.

Re:A Quiz About Integers in C by caf on Sunday June 03, 2012 @11:34PM (#4062545)
It's not true that (unsigned)INT_MAX + 1 is never 0 - it's allowed for UINT_MAX == INT_MAX (leaving the sign bit unused in the unsigned representation). I've never seen such an implementation, though.
Re:A Quiz About Integers in C by jacquesgt on Monday June 04, 2012 @01:08AM (#4062766)
Yep, you're right.
Re:A Quiz About Integers in C by matheusalmeida on Monday June 04, 2012 @04:12AM (#4063098)
Yes, my mistake. I meant UINT_MAX + 1.
Re:A Quiz About Integers in C by gegenschall on Monday June 04, 2012 @04:17AM (#4063111)
There is a somewhat related text by Fefe: http://www.fefe.de/intof.html