Comment

Comment by olliej

The issue isn’t what the hardware can do, but rather that the C spec leaves it undefined. Over the last decade have increasingly abused this idea basically making the spec a land mine of UB and then claiming that UB allows them to do whatever they want, even when the programmer intent is obvious.

That said in modern clang and gcc you can (and should) use the overflow builtins which are all essentially:

  Bool __builtin_[operation]_overflow(type a, type b, type* out)
Returning true if the operation overflowed. These produce “ideal” code, e.g

if(overflowoperation(x,y,&out)) ...

Produces the platform branch on overflow instructions.

parent olliej 8 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton