title: Undefined behavior Clang vs gcc vs VC
body: <p>There are some undefined behavior examples in C/C++ which I was trying on my computer in order to see whether they indeed gave different results each time I ran the code. I noticed that within the same compiler, all the runs gave the same result. So my first question is, is this really undefined behavior?</p>
  
  <p>The second question: How come when I change my compiler from clang to vs, the results change? What can be the root cause of this?</p>
  
  <p>Example 1:</p>
  
  <pre><code>    #include &lt;stdio.h&gt;
  
      int main (int argc, char *argv[])
      {
  
        int i = 1;
        int v = 2;
        i = i++ + v;
        printf("%d\n", i);
  
        return 0;
      }
  </code></pre>
  
  <p>In Clang and gcc the result is always 3. While in vc, the result is always 4.</p>
  
  <p>Another example with integer overflow:</p>
  
  <pre><code>int main (int argc, char *argv[])
  {
  
    int i = 1;
    int v = 2;
    i = i++ + v;
    printf("%d\n", i);
  
  
    return 0;
  }
  </code></pre>
  
  <p>Clang gives always a totaly diferent result (which I consider as undefined behavior) while gcc always give the same result -2147483648.</p>
  
  <p>I expect the results to vary depending on which machine they use (for example 2 complement) not to vary between compilers.</p>
  
  <p>So my questions in a nutshell: 1) what is ment by undefined behavior and 2) how come the results differ from compiler to compiler?</p>