title: When undefined behavior can be considered well-known and accepted?
body: <p>We know what undefined behavior is and we (more or less) know the reasons (performance, cross-platform compatibility) of most of them. Assuming a given platform, say Windows 32 bit, can we consider an undefined behavior as <em>well-known</em> and consistent across the platform? I understand <strong>there is not a general answer</strong> then I would <strong>restrict to two common UB</strong> I see pretty often in production code (in use from years).</p>
  
  <p>1) <a href="https://stackoverflow.com/a/1812359/1207195">Reference</a>. Give this <code>union</code>:</p>
  
  <pre><code>union {
      int value;
      unsigned char bytes[sizeof(int)];
  } test;
  </code></pre>
  
  <p>Initialized like this:</p>
  
  <pre><code>test.value = 0x12345678;
  </code></pre>
  
  <p>Then accessed with:</p>
  
  <pre><code>for (int i=0; i &lt; sizeof(test.bytes); ++i)
      printf("%d\n", test.bytes[i]);
  </code></pre>
  
  <p>2) <a href="https://stackoverflow.com/a/4810460/1207195">Reference</a>. Given an array of unsigned <code>short*</code> casting to (for example) <code>float*</code> and accessing it (<a href="https://stackoverflow.com/q/1676385/1207195">reference</a>, no padding between array members).</p>
  
  <p><strong>Is code relying on <em>well-known</em> UBs (like those) working <em>by case</em></strong> (assuming compiler may change and for sure compiler version will change for sure) or even if they're UB for cross-platform code they rely on platform specific details (then it won't change if we don't change platform)? Does same reasoning apply also to <em>unspecified</em> behavior (when compiler documentation doesn't say anything about it)?</p>
  
  <p><strong>EDIT</strong> According to <a href="https://stackoverflow.com/a/6725981/1207195">this post</a> starting from C99 type punning is just <em>unspecified</em>, not <em>undefined</em>.</p>