HNHacker News
TopNewBestAskShowJobs

lilllly

8 karma · joined November 28, 2022

submissionscomments
lilllly··on GCC undefined behaviors are getting wild
I can easily test if n+1 is < n with fwrapv.

Without you have to do convoluted things like rearranging the expression to unnatural forms (move the addition to the right but invert to subtraction, etc), special case INT_MAX/INT_MIN, and so on - which you then have to hope the compiler is smart enough to optimize, which it often isn't (oh how ironic).

lilllly··on GCC undefined behaviors are getting wild
We need a -fsane-c

Then they can add a #pragma optimize(assumes=no-int-overflow, whatever, etc) to precisely add optimizations when needed and you 'know' its safe.