News for hackers. Stuff that matters.
Re:C for All by yorwba on Friday March 23, 2018 @11:17PM (#16664616)
Your "small_increment" needs to be at least large enough to turn the smallest negative int into a non-negative number, and that makes it unrepresentable as a signed int itself.

There are cases where the compiler removes misguided overflow checks, since "perform UB, then check whether it happened" doesn't actually work, but your example is not such a case.

Re:C for All by loup-vaillant on Saturday March 24, 2018 @10:12AM (#16666664)
> "perform UB, then check whether it happened" doesn't actually work

This raises an interesting point, because in many cases, assuming 2's complement and wrapping around, checking for overflow after the fact, as opposed to preventing it from happening in the first place, is actually easier. (And actually works if you use the `-fwrap` flag.)

The right thing should be easier to do than the wrong thing. It's a shame this is not the case here.

Re:C for All by loup-vaillant on Saturday March 24, 2018 @07:15AM (#16666034)
I was of course assuming that `whatever` was positive, and the compiler knew it. See this sibling thread: https://news.ycombinator.com/item?id=16664546