title: Integer overflow in C: standards and compilers
body: <p><em>Edited to include proper standard reference thanks to Carl Norum.</em></p>
  
  <p>The C standard states</p>
  
  <blockquote>
    <p>If an <em>exceptional condition</em> occurs during the evaluation of an expression (that is, if the result is not mathematically defined or not in the range of representable values for its type), the behavior is undefined.</p>
  </blockquote>
  
  <p>Are there compiler switches that guarantee certain behaviors on integer overflow?  I'd like to avoid nasal demons.  In particular, I'd like to force the compiler to wrap on overflow.</p>
  
  <p>For the sake of uniqueness, let's take the standard to be C99 and the compiler to be gcc.  But I would be interested in answers for other compilers (icc, cl) and other standards (C1x, C89).  In fact, just to annoy the C/C++ crowd, I'd even appreciate answers for C++0x, C++03, and C++98.</p>
  
  <p>Note: International standard ISO/IEC 10967-1 may be relevant here, but as far as I could tell it was mentioned only in the informative annex.</p>