<story><title>Catch-23: The New C Standard Sets the World on Fire</title><url>https://queue.acm.org/detail.cfm?id=3588242</url></story><parent_chain><item><author>Dylan16807</author><text>&amp;gt; C23 furthermore gives the compiler license to use an unreachable annotation on one code path to justify removing, without notice or warning, an entirely different code path that is not marked unreachable: see the discussion of puts() in Example 1 on page 316 of N3054.9&lt;p&gt;I don&amp;#x27;t agree with that description at all.  Here&amp;#x27;s the code:&lt;p&gt;&lt;pre&gt;&lt;code&gt;  1 if (argc &amp;lt;= 2)
  2   unreachable();
  3 else
  4   return printf(&amp;quot;%s: we see %s&amp;quot;, argv[0], argv[1]);
  5 return puts(&amp;quot;this should never be reached&amp;quot;);
&lt;/code&gt;&lt;/pre&gt;
The only code path that&amp;#x27;s &amp;quot;entirely different&amp;quot; is lines 1,4,5 and in that case of course you remove a return that&amp;#x27;s after a return.&lt;p&gt;And the other valid code path is 1,2,5, which has `puts` after `unreachable`.&lt;p&gt;To need `puts` you have to imagine a code path that gets past the &amp;quot;if&amp;quot; without taking either branch?&lt;p&gt;Maybe the author means something by &amp;quot;code path&amp;quot; that&amp;#x27;s very different from how I interpret it?&lt;p&gt;I would be pretty surprised if the above code means something different from:&lt;p&gt;&lt;pre&gt;&lt;code&gt;  if (argc &amp;lt;= 2) {
    unreachable();
    return puts(&amp;quot;this should never be reached&amp;quot;);
  } else {
    return printf(&amp;quot;%s: we see %s&amp;quot;, argv[0], argv[1]);
    return puts(&amp;quot;this should never be reached&amp;quot;);
  }&lt;/code&gt;&lt;/pre&gt;</text></item></parent_chain><comment><author>ternaryoperator</author><text>This reminds me of a point made by the late Stan Kelly-Bootle, who for years wrote the Devil&amp;#x27;s Advocate column in UNIX Review magazine. In the early 1990s, he was discussing Microsoft&amp;#x27;s new C compiler and noted that in the promo material for the new compiler, it showed a benchmark for a loop that counted from 1 to 10,000 then printed &amp;quot;Hello&amp;quot;. MS claimed that without optimization it took a few milliseconds, after optimization: 0 ms. A small asterisk explained the optimizer simply removed the loop. Kelly-Bootle pointed out, that the only reason a developer would write such a loop was to introduce a needed delay. Therefore, deleting the loop was not optimizing, but in fact pessimizing. And so, it was in fact Microsoft&amp;#x27;s Pessimizing C compiler.</text></comment>
<story><title>Catch-23: The New C Standard Sets the World on Fire</title><url>https://queue.acm.org/detail.cfm?id=3588242</url></story><parent_chain><item><author>Dylan16807</author><text>&amp;gt; C23 furthermore gives the compiler license to use an unreachable annotation on one code path to justify removing, without notice or warning, an entirely different code path that is not marked unreachable: see the discussion of puts() in Example 1 on page 316 of N3054.9&lt;p&gt;I don&amp;#x27;t agree with that description at all.  Here&amp;#x27;s the code:&lt;p&gt;&lt;pre&gt;&lt;code&gt;  1 if (argc &amp;lt;= 2)
  2   unreachable();
  3 else
  4   return printf(&amp;quot;%s: we see %s&amp;quot;, argv[0], argv[1]);
  5 return puts(&amp;quot;this should never be reached&amp;quot;);
&lt;/code&gt;&lt;/pre&gt;
The only code path that&amp;#x27;s &amp;quot;entirely different&amp;quot; is lines 1,4,5 and in that case of course you remove a return that&amp;#x27;s after a return.&lt;p&gt;And the other valid code path is 1,2,5, which has `puts` after `unreachable`.&lt;p&gt;To need `puts` you have to imagine a code path that gets past the &amp;quot;if&amp;quot; without taking either branch?&lt;p&gt;Maybe the author means something by &amp;quot;code path&amp;quot; that&amp;#x27;s very different from how I interpret it?&lt;p&gt;I would be pretty surprised if the above code means something different from:&lt;p&gt;&lt;pre&gt;&lt;code&gt;  if (argc &amp;lt;= 2) {
    unreachable();
    return puts(&amp;quot;this should never be reached&amp;quot;);
  } else {
    return printf(&amp;quot;%s: we see %s&amp;quot;, argv[0], argv[1]);
    return puts(&amp;quot;this should never be reached&amp;quot;);
  }&lt;/code&gt;&lt;/pre&gt;</text></item></parent_chain><comment><author>wahern</author><text>I think the point is that if the `argc &amp;lt;= 2` path is unreachable, then that means argc is &lt;i&gt;always&lt;/i&gt; greater than 2, permitting the compiler to optimize the entire block to just:&lt;p&gt;&lt;pre&gt;&lt;code&gt;  return printf(&amp;quot;%s: we see %s&amp;quot;, argv[0], argv[1]);
&lt;/code&gt;&lt;/pre&gt;
IOW, the conditional has been elided. But you&amp;#x27;re right in that the wording of the complaint doesn&amp;#x27;t match the example. The author presumably had in mind some of the more infamous NULL pointer-related optimizations, without spending the time to put together a properly analogous example.</text></comment>