title: Fixpoint-Overflow-Traps for int16_t and int8_t
body: <p>I have a complicated program with fixed-point arithmetic.</p>
  
  <p>It seems that there are occasional overflows. </p>
  
  <p>To find them I have set the flag <code>-ftrapv</code>. This seems to work only with <code>int32_t</code>. Is that correct? </p>
  
  <p>Is there a way to achieve the same behavior with <code>int16_t</code> and <code>int8_t</code>?</p>
  
  <p>Here is my test code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdint.h&gt;
  
  int main(void)
  {
      int8_t int8 = 127;
      int8 += 1;
      printf("int8: %d\n",int8);
  
      int16_t int16 = 32767;
      int16 += 1;
      printf("int16: %d\n",int16);
  
      int32_t int32 = 2147483647;
      int32 += 1;
      printf("int32: %d\n",int32);
  }
  </code></pre>
  
  <p>I compile with:</p>
  
  <pre><code>rm a.out; gcc -ftrapv main.c &amp;&amp; ./a.out
  </code></pre>
  
  <p>and get:</p>
  
  <pre><code>int8: -128
  int16: -32768
  Aborted
  </code></pre>
  
  <p>My compiler version is <code>gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609</code>.</p>
  
  <p>Note: Some of the answers refer to a test program that I have incorrectly written before.</p>