title: How to check for signed integer overflow in C without undefined behaviour?
body: <p>There's (1):</p>
  
  <pre><code>// assume x,y are non-negative
  if(x &gt; max - y) error;
  </code></pre>
  
  <p>And (2):</p>
  
  <pre><code>// assume x,y are non-negative
  int sum = x + y;
  if(sum &lt; x || sum &lt; y) error;
  </code></pre>
  
  <p>Whichs is preferred or is there a better way.</p>