The Strict Aliasing Situation Is Pretty Bad
I thought this article was unnecessarily dire.<p>One section claims &quot;Physical Subtyping is Broken&quot;, where &quot;physical subtyping&quot; is defined as &quot;the struct-based implementation of inheritance in C.&quot;  I assume this means the typical pattern of:<p><pre><code>    typedef struct {
       int base_member_1;
       int base_member_2;
    } Base;

    typedef struct {
       Base base;

       int derived_member 1;
    } Derived;
</code></pre>
The article claims physical subtyping is broken because casting between pointer types results in undefined behavior.  The article gives this example:<p><pre><code>    #include &lt;stdio.h&gt;
     
    typedef struct { int i1; } s1;
    typedef struct { int i2; } s2;
     
    void f(s1 *s1p, s2 *s2p) {
      s1p-&gt;i1 = 2;
      s2p-&gt;i2 = 3;
      printf(&quot;%i\n&quot;, s1p-&gt;i1);
    }
     
    int main() {
      s1 s = {.i1 = 1};
      f(&amp;s, (s2 *)&amp;s);
    }
</code></pre>
I agree this example is broken, but casting between pointer types in this way is totally unnecessary for C-based inheritance.  You can do upcasts and downcasts that are totally legal:<p><pre><code>    Derived d;

    &#x2F;&#x2F; Legal upcast:
    Base* base = &amp;d-&gt;base;

    &#x2F;&#x2F; Legal downcast:
    Derived* derived = (Derived*)base;
</code></pre>
So I don&#x27;t think the article has proved that &quot;Physical Subtyping is Broken.&quot;<p>The next section says that &quot;Chunking Optimizations Are Broken,&quot; because code like this is illegal:<p><pre><code>    void copy_8_bytes(char *dst, const char *src) {
      *(uint64_t*)dst = *(uint64_t*)src;
    }
</code></pre>
While this is true, such optimizations are generally unnecessary.  For example, write this instead as:<p><pre><code>    void copy_8_bytes(char *dst, const char *src) {
      memcpy(dst, src, 8);
    }
</code></pre>
If you compile this on an architecture like x86 that truly allows unaligned reads, you&#x27;ll see that modern compilers do the &quot;chunking optimization&quot; for you:<p><pre><code>    0000000000000000 &lt;copy_8_bytes&gt;:
       0:   48 8b 06                mov    rax,QWORD PTR [rsi]
       3:   48 89 07                mov    QWORD PTR [rdi],rax
       6:   c3                      ret
</code></pre>
It says next that &quot;int8_t and uint8_t Are Not Necessarily Character Types.&quot;  That is indeed a good point and probably not well-known.  So I agree this is something people should keep in mind.  But most of this article is warning against practices that are generally unnecessary and known to be bad C in 2016.<p>It&#x27;s true that a lot of legacy code-bases still break these rules.  But many are cleaning up their act, fixing practices that were never correct but used to work.  For example, here is an example of Python fixing its API to comply with strict aliasing, and this is from almost 10 years ago: <a href="https:&#x2F;&#x2F;www.python.org&#x2F;dev&#x2F;peps&#x2F;pep-3123&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.python.org&#x2F;dev&#x2F;peps&#x2F;pep-3123&#x2F;</a>