<story><title>Type Punning Functions in C</title><url>http://www.evanmiller.org/type-punning-functions-in-c.html</url></story><parent_chain><item><author>pklausler</author><text>If your C compiler doesn&amp;#x27;t complain bitterly to you about an incompatible pointer type on that assignment, get a better C compiler.  If your C compiler does complain bitterly about it, heed those warnings or expect no sympathy.&lt;p&gt;If you write this in production code, and don&amp;#x27;t get sent home that day in tears, your company&amp;#x27;s code review process has failed.</text></item></parent_chain><comment><author>MaulingMonkey</author><text>&amp;gt; If your C compiler doesn&amp;#x27;t complain bitterly to you about an incompatible pointer type on that assignment, get a better C compiler.&lt;p&gt;The example code uses C style casts, which is C-speak for &amp;quot;fuck off compiler I know what I&amp;#x27;m doing.&amp;quot;  I&amp;#x27;d like to see what warnings your compiler produces.  VS2015 &amp;#x2F;W4 &amp;#x2F;ANALYZE produces nothing, and neither do clang nor GCC from the looks of it.&lt;p&gt;That people C cast without knowing what they&amp;#x27;re doing is rather unfortunate tragedy.  That this is a common enough problem, that the Win32 API is littered with backwards compatability hacks where someone C-casted away ABI differences turns it into a statistic.&lt;p&gt;&amp;gt; If you write this in production code, and don&amp;#x27;t get sent home that day in tears, your company&amp;#x27;s code review process has failed.&lt;p&gt;Assuming we&amp;#x27;re talking &amp;quot;well meaning newbie&amp;quot; instead of &amp;quot;sanity hating self-flagellating freak and&amp;#x2F;or undefined behavior worshiping cultist&amp;quot;, I prefer to carefully explain that they&amp;#x27;ve invoked undefined behavior, that undefined behavior leads to crunching to find optimizer induced heisenbugs in the weeks before we ship, and to impress upon them that this is why we never cast away even &amp;quot;trivial&amp;quot; and &amp;quot;minor&amp;quot; function pointer differences.  And then, when they ask what the &lt;i&gt;correct&lt;/i&gt; thing to do is, point out the API docs and header both have this little &amp;quot;WINAPI&amp;quot; annotation they can use.  Hey!  No more casts!  &lt;i&gt;Easier&lt;/i&gt; than the casts too.  Win&amp;#x2F;win.&lt;p&gt;However, if we &lt;i&gt;are&lt;/i&gt; talking about the &amp;quot;sanity hating self-flagellating freak and&amp;#x2F;or undefined behavior worshiping cultist&amp;quot;, I can only recommend nuking the site from orbit.  It&amp;#x27;s the only way to be sure.  If their home isn&amp;#x27;t part of the radioactive crater, you didn&amp;#x27;t use large enough nukes, and your company&amp;#x27;s code review process has failed.</text></comment>
<story><title>Type Punning Functions in C</title><url>http://www.evanmiller.org/type-punning-functions-in-c.html</url></story><parent_chain><item><author>pklausler</author><text>If your C compiler doesn&amp;#x27;t complain bitterly to you about an incompatible pointer type on that assignment, get a better C compiler.  If your C compiler does complain bitterly about it, heed those warnings or expect no sympathy.&lt;p&gt;If you write this in production code, and don&amp;#x27;t get sent home that day in tears, your company&amp;#x27;s code review process has failed.</text></item></parent_chain><comment><author>coldtea</author><text>&amp;gt;&lt;i&gt;If your C compiler doesn&amp;#x27;t complain bitterly to you about an incompatible pointer type on that assignment, get a better C compiler.&lt;/i&gt;&lt;p&gt;Yeah? So which compiler do you have in mind exactly we should use?</text></comment>