title: unsigned integer addition and undefined behavior in C90
body: <h2>Solved!</h2>
  
  <p>The relevant passage can be found in C90 ISO 9899:1990 6.1.2.5 Types:</p>
  
  <blockquote>
    <p>"[..] A computation involving unsigned operands can never overflow, because [...]" </p>
  </blockquote>
  
  <p>Therefore 9899:1990 6.3 can not apply and can therefore not be undefined behavior.</p>
  
  <ul>
  <li>C90: see the <a href="https://stackoverflow.com/a/22151834/3364914">full answer</a> below.</li>
  <li>C99: see the <a href="https://stackoverflow.com/a/7221449/3364914">answer</a> for <a href="https://stackoverflow.com/q/7221409/3364914">"Is unsigned integer subtraction defined behavior?"</a></li>
  </ul>
  
  <p>Thanks to Keith Thompson for helping me read. :-)</p>
  
  <p><b>[2014-03-14] </b> Apparently unsigned short integer can overflow resulting in undefined behavior depending on the target environment. This can happen if short unsigned integer become arithmetically promoted to int. Details see <a href="https://stackoverflow.com/a/22151834/3364914">updated answer</a> and the comments of supercat. Thanks to both. :-)</p>
  
  <h2>Original Question:</h2>
  
  <p>First of all, sorry for my bad English... I try my best. This is my first question and I think a quite stupid one.</p>
  
  <p>For some sad reasons, my company got stuck to still ANSI C90 (ANSI/ISO 9899:1990) and so I have an old copy of this standard in my hands, but still missing the Corrections and ademnends.</p>
  
  <p>I have an really easy question, and had known the answer perfectly well in times of my studies - till I try to read it up in the standard.</p>
  
  <p>What happens if I have an unsigned integer overflow on an addition. Please see this piece of code:</p>
  
  <pre><code>uint32_t a,b,c;
  b = UINT_MAX;
  c = UINT_MAX;
  a = b + c; /* Overflow here - undefined behavior? */
  </code></pre>
  
  <p>All I ever know about that is, that unsigned integer just wraps around as long as needed and everything is fine, while not always intended.</p>
  
  <p>Now I was looking for the corresponding parts in the standard.</p>
  
  <p>There is of course ISO 9899:1990 6.2.1.2 which describe the wrap around for unsigned integers, whenever it is converted. And there is a little bit of 6.2.1.5 "usual arithmetic conversions", which describe how the types are become wider, mostly that both operands of an expression have the same type.</p>
  
  <p>Now there is 6.3 "Expressions" which is concerning me. I cite:</p>
  
  <blockquote>
    <p>"[...]
    If an exception 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>And the chapter 6.3.6 about additive operators says:</p>
  
  <ul>
  <li>usual arithmetic conversions on operands, which does not apply as everything is uint32_t.</li>
  <li>and the result is the sum of both, which clearly does not fit into uint32_t.</li>
  <li>FINE</li>
  </ul>
  
  <p>Nothing is said, that the resulting value is converted to the result type - so 6.2.1.2 does not apply. But the value then clearly overflows, where 6.3 steps in.</p>
  
  <p>As far as I can see - this is undefined behavior according to ISO 9899:1990. What did I miss? Is there something in the Corrigendae? Have I miss a line or word in the standard?</p>
  
  <p>I am really confused now. :-)</p>
  
  <p>With regards,
  Mark</p>
  
  <h2>Question Update</h2>
  
  <p><b>[2014-03-03]</b> Solved</p>
  
  <p><b>[2014-03-03]</b>
  So thanks to Acme I now have a clear and complete answer <b>for ANSI C99</b> (see answer to:
  <a href="https://stackoverflow.com/a/7221449/3364914">"Is unsigned integer subtraction defined behavior"</a>: It is <b>clear defined behavior as expected</b>. And though I expect this <b>for ANSI C90</b> also, I still can't read it out of the text of ISO 9899:1990, given the text passages above. So I consider my question <b>still unanswered</b> for the moment.</p>
  
  <p>Edit: Just Typos | Edit2: add C90 &amp; standards tags | Edit3: add Question Update | Edit4: add solved section | Edit5: add answer links :-) | Edit6: Update short unsigned integer overflows | Edit7: some typos </p>