<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: outsmarted by the compiler again. (bug?) in CodeWarrior for QorIQ</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-QorIQ/outsmarted-by-the-compiler-again-bug/m-p/154502#M1908</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Seems logical to me. An unsigned long can only be &amp;gt;= 0, so the outcome of the if must always be true...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 02 Aug 2011 17:38:35 GMT</pubDate>
    <dc:creator>vier_kuifjes</dc:creator>
    <dc:date>2011-08-02T17:38:35Z</dc:date>
    <item>
      <title>outsmarted by the compiler again. (bug?)</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-QorIQ/outsmarted-by-the-compiler-again-bug/m-p/154501#M1907</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;static unsigned long ArrayInIdx&amp;nbsp; =0;static unsigned long ArrayOutIdx =0;void test1(void) {&amp;nbsp;&amp;nbsp; unsigned long idx = ArrayInIdx;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // get array index&amp;nbsp;&amp;nbsp; if( -16L+idx-ArrayOutIdx &amp;gt;= 0 )&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // not full ? (less than 16)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return;&amp;nbsp;&amp;nbsp; ArrayInIdx++;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // allocate array element}void test2(void) {&amp;nbsp;&amp;nbsp; unsigned long idx = ArrayInIdx;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // get array index&amp;nbsp;&amp;nbsp; if( idx-ArrayOutIdx &amp;gt;= 16L )&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // not full ? (less than 16)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return;&amp;nbsp;&amp;nbsp; ArrayInIdx++;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // allocate array element}static signed long sArrayInIdx&amp;nbsp; =0;static signed long sArrayOutIdx =0;void test3(void) {&amp;nbsp;&amp;nbsp; signed long idx = sArrayInIdx;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // get array index&amp;nbsp;&amp;nbsp; if( -16L+idx-sArrayOutIdx &amp;gt;= 0 )&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // not full ? (less than 16)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return;&amp;nbsp;&amp;nbsp; sArrayInIdx++;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // allocate array element}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The test1() function compiles to a single rts, ie. the compiler thinks the condition is always true.&lt;/P&gt;&lt;P&gt;The other two compile as intended.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Am i wrong to assume that the argument of the 'if' always&amp;nbsp;is signed ?&lt;/P&gt;&lt;P&gt;Is the compiler messing up ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;( PS: CW7.2se )&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 08:58:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-QorIQ/outsmarted-by-the-compiler-again-bug/m-p/154501#M1907</guid>
      <dc:creator>MrBean</dc:creator>
      <dc:date>2020-10-29T08:58:07Z</dc:date>
    </item>
    <item>
      <title>Re: outsmarted by the compiler again. (bug?)</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-QorIQ/outsmarted-by-the-compiler-again-bug/m-p/154502#M1908</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Seems logical to me. An unsigned long can only be &amp;gt;= 0, so the outcome of the if must always be true...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Aug 2011 17:38:35 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-QorIQ/outsmarted-by-the-compiler-again-bug/m-p/154502#M1908</guid>
      <dc:creator>vier_kuifjes</dc:creator>
      <dc:date>2011-08-02T17:38:35Z</dc:date>
    </item>
    <item>
      <title>Re: outsmarted by the compiler again. (bug?)</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-QorIQ/outsmarted-by-the-compiler-again-bug/m-p/154503#M1909</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It seems i assumed promotion rules wrongly.&lt;/P&gt;&lt;P&gt;Mixing signed and unsigned in the if argument promotes to unsigned, i assumed signed.&lt;/P&gt;&lt;P&gt;Didnt know, didnt seem logical to me.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Aug 2011 18:23:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-QorIQ/outsmarted-by-the-compiler-again-bug/m-p/154503#M1909</guid>
      <dc:creator>MrBean</dc:creator>
      <dc:date>2011-08-02T18:23:54Z</dc:date>
    </item>
  </channel>
</rss>

