Implementing / enforcing wraparound arithmetic in C : <p>The C standard says that overflow in arithmetic is undefined.</p>

<p>I would like to know how to implement wraparound arithmetic in a performance-friendly way. This means that overflow checking solutions like presented <a href="https://www.securecoding.cert.org/confluence/display/c/INT32-C.+Ensure+that+operations+on+signed+integers+do+not+result+in+overflow" rel="nofollow noreferrer">here</a> are not an option (as they slow the operation by about an order of magnitude).</p>

<p>I assume the solution would involve writing an assembly routine to do this. Is there a library available that does this (preferably for multiple architecture, although x86 is a must)?</p>

<p>Alternatively, is there a compiler flag (for gcc &amp; clang) that makes the compiler enforce wraparound semantics for integer arithmetic?</p>
