<?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: Function does not get the correct passed argunment in CodeWarrior for MCU</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Function-does-not-get-the-correct-passed-argunment/m-p/172129#M5355</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Daniel,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your answer.&amp;nbsp; Yes, the "implicitly declared function" warning was there.&amp;nbsp; After I put in function prototypes, then the problem goes away.&amp;nbsp; I was wondering if it is possible to make this into an error instead of warning?&amp;nbsp; Mismatch function prototype should be considered a very serious mistake and should be regarded as error to make sure the programmer fix it before going on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The other problem should be just regarded as&amp;nbsp;the debugger watch window problem which should not affect the normal&amp;nbsp;operation of the code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 28 Dec 2010 09:22:15 GMT</pubDate>
    <dc:creator>HYIU</dc:creator>
    <dc:date>2010-12-28T09:22:15Z</dc:date>
    <item>
      <title>Function does not get the correct passed argunment</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Function-does-not-get-the-correct-passed-argunment/m-p/172127#M5353</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new,courier'; font-size: 2;"&gt;Hi expert,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new,courier'; font-size: 2;"&gt;I have a simple program running in HCS08AC128 simulation mode.&amp;nbsp; I found that the argunment passed&amp;nbsp;to a&amp;nbsp;function cannot be correctly received by the function.&amp;nbsp; In main, I call this function SD_CLKDelay (8).&amp;nbsp; This is the function:&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new,courier'; font-size: 2;"&gt;&amp;nbsp; void SD_CLKDelay (byte Frames)&lt;BR /&gt;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; while (Frames--)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; SPI_Send_byte (0xFF);&lt;BR /&gt;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new,courier'; font-size: 2;"&gt;Now, if I single step [F5] into this function, the variable Frames should show 8, but instead it&lt;/SPAN&gt;&lt;SPAN style="font-family: 'courier new,courier'; font-size: 2;"&gt;&amp;nbsp;shows 0x21 in the variable window.&amp;nbsp;&amp;nbsp;Here is&amp;nbsp;assembly for&amp;nbsp;main calling:&lt;/SPAN&gt;&lt;/P&gt;&lt;P align="left" style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P align="left" style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P align="left"&gt;&lt;SPAN style="font-family: 'courier new,courier'; font-size: 2;"&gt;&amp;nbsp; 0014 a608&amp;nbsp;&amp;nbsp; [2]&amp;nbsp; LDA #8&lt;/SPAN&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;SPAN style="font-family: 'courier new,courier'; font-size: 2;"&gt;&amp;nbsp; 0016 cd0000 [6]&amp;nbsp; JSR SD_CLKDelay&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new,courier'; font-size: 2;"&gt;but the logic of the&amp;nbsp;function is still&amp;nbsp;correct when looking at the assembly&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P align="left" style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P align="left" style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P align="left"&gt;&lt;SPAN style="font-family: 'courier new,courier';"&gt;&amp;nbsp; 0000 2008&amp;nbsp;&amp;nbsp; [3]&amp;nbsp; BRA LA ;abs = 000a&lt;/SPAN&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;SPAN style="font-family: 'courier new,courier';"&gt;&amp;nbsp; 0002 L2:&lt;/SPAN&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;SPAN style="font-family: 'courier new,courier';"&gt;&amp;nbsp; 0002 aeff&amp;nbsp;&amp;nbsp; [2]&amp;nbsp; LDX #-1&lt;/SPAN&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;SPAN style="font-family: 'courier new,courier';"&gt;&amp;nbsp; 0004 8c&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [1]&amp;nbsp; CLRH&lt;/SPAN&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;SPAN style="font-family: 'courier new,courier';"&gt;&amp;nbsp; 0005 87&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [2]&amp;nbsp; PSHA&lt;/SPAN&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;SPAN style="font-family: 'courier new,courier';"&gt;&amp;nbsp; 0006 cd0000 [6]&amp;nbsp; JSR SPI_Send_byte&lt;/SPAN&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;SPAN style="font-family: 'courier new,courier';"&gt;&amp;nbsp; 0009 86&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [3]&amp;nbsp; PULA&lt;/SPAN&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;SPAN style="font-family: 'courier new,courier';"&gt;&amp;nbsp; 000a LA:&lt;/SPAN&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;SPAN style="font-family: 'courier new,courier';"&gt;&amp;nbsp; 000a 97&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [1]&amp;nbsp; TAX&lt;/SPAN&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;SPAN style="font-family: 'courier new,courier';"&gt;&amp;nbsp; 000b 4a&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [1]&amp;nbsp; DECA&lt;/SPAN&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;SPAN style="font-family: 'courier new,courier';"&gt;&amp;nbsp; 000c 5d&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [1]&amp;nbsp; TSTX&lt;/SPAN&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;SPAN style="font-family: 'courier new,courier';"&gt;&amp;nbsp; 000d 26f3&amp;nbsp;&amp;nbsp; [3]&amp;nbsp; BNE L2 ;abs = 0002&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new,courier'; font-size: 2;"&gt;but when I single step and&amp;nbsp;goes to&amp;nbsp;inside the&amp;nbsp;SPI_Send_byte() function, the variable is wrong and the actual behavior is also wrong.&amp;nbsp; Here is what happen in the assembly:&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; font-size: 2;"&gt;&amp;nbsp; 0000 87&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [2]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PSHA&amp;nbsp;&lt;BR /&gt;&amp;nbsp; 0001&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; L1:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; 0001 0b00fd&amp;nbsp;&amp;nbsp; [5]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BRCLR 5,_SPI1S,L1 ;abs = 0001&lt;BR /&gt;&amp;nbsp; 0004 b600&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [3]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LDA&amp;nbsp;&amp;nbsp; _SPI1S&lt;BR /&gt;&amp;nbsp; 0006 95&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [2]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TSX&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; 0007 f6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [3]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LDA&amp;nbsp;&amp;nbsp; ,X&lt;BR /&gt;&amp;nbsp; 0008 b700&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [3]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; STA&amp;nbsp;&amp;nbsp; _SPI1D&lt;BR /&gt;&amp;nbsp; 000a&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LA:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; 000a 0f00fd&amp;nbsp;&amp;nbsp; [5]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BRCLR 7,_SPI1S,LA ;abs = 000a&lt;BR /&gt;&amp;nbsp; 000d b600&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [3]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LDA&amp;nbsp;&amp;nbsp; _SPI1D&lt;BR /&gt;&amp;nbsp; 000f 8a&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [3]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PULH&amp;nbsp;&lt;BR /&gt;&amp;nbsp; 0010 81&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [6]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RTS&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new,courier'; font-size: 2;"&gt;Now it is obvious that the argunment&amp;nbsp;0xFF passed to the function&amp;nbsp;is lost.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; font-size: 2;"&gt;So there are two problems:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; font-size: 2;"&gt;1. Why the compiler compile the code incorrectly?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; font-size: 2;"&gt;2. Why the debugger simulator showing the incorrect variable values?&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; font-size: 2;"&gt;I am using the latest CodeWarrior Development Studio just downloaded from Freescale, and using all the default build configuration.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new,courier'; font-size: 2;"&gt;BR - Henry&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 Dec 2010 11:21:11 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Function-does-not-get-the-correct-passed-argunment/m-p/172127#M5353</guid>
      <dc:creator>HYIU</dc:creator>
      <dc:date>2010-12-24T11:21:11Z</dc:date>
    </item>
    <item>
      <title>Re: Function does not get the correct passed argunment</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Function-does-not-get-the-correct-passed-argunment/m-p/172128#M5354</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Do you have any compiler warnings about&amp;nbsp;implicitly&amp;nbsp;declared functions? Take those very seriously, if the implied type does not 100% match the actual type then such argument passing bugs are happening. And the&amp;nbsp;implicitly&amp;nbsp;deduced types rarely match the declared ones, ....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 25 Dec 2010 04:57:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Function-does-not-get-the-correct-passed-argunment/m-p/172128#M5354</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2010-12-25T04:57:09Z</dc:date>
    </item>
    <item>
      <title>Re: Function does not get the correct passed argunment</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Function-does-not-get-the-correct-passed-argunment/m-p/172129#M5355</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Daniel,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your answer.&amp;nbsp; Yes, the "implicitly declared function" warning was there.&amp;nbsp; After I put in function prototypes, then the problem goes away.&amp;nbsp; I was wondering if it is possible to make this into an error instead of warning?&amp;nbsp; Mismatch function prototype should be considered a very serious mistake and should be regarded as error to make sure the programmer fix it before going on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The other problem should be just regarded as&amp;nbsp;the debugger watch window problem which should not affect the normal&amp;nbsp;operation of the code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Dec 2010 09:22:15 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Function-does-not-get-the-correct-passed-argunment/m-p/172129#M5355</guid>
      <dc:creator>HYIU</dc:creator>
      <dc:date>2010-12-28T09:22:15Z</dc:date>
    </item>
    <item>
      <title>Re: Function does not get the correct passed argunment</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Function-does-not-get-the-correct-passed-argunment/m-p/172130#M5356</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can set the C compiler options to regard "implicitly declared function" warnings as an error instead:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;option -Wpd in the C compiler options.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also available in the drop down menu Edit&amp;gt;XXXX Settings&amp;gt;Compiler for HCXX&amp;gt;Messages&amp;gt;Error for implicit parameter declaration&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;(default is unclicked and disabled)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Dec 2010 02:17:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Function-does-not-get-the-correct-passed-argunment/m-p/172130#M5356</guid>
      <dc:creator>Emac</dc:creator>
      <dc:date>2010-12-31T02:17:28Z</dc:date>
    </item>
    <item>
      <title>Re: Function does not get the correct passed argunment</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Function-does-not-get-the-correct-passed-argunment/m-p/172131#M5357</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think this should be an error as well. If I remember correctly, declaring functions without a prototype is considered an obsolete part of the C language by the standard committee, and they will likely remove it from the language should there ever be a new standard released.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Jan 2011 15:19:32 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Function-does-not-get-the-correct-passed-argunment/m-p/172131#M5357</guid>
      <dc:creator>Lundin</dc:creator>
      <dc:date>2011-01-03T15:19:32Z</dc:date>
    </item>
  </channel>
</rss>

