<?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>CodeWarrior for MCUのトピックRe: type casting in CW12 V3.1</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/type-casting-in-CW12-V3-1/m-p/135839#M1780</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Pointer types&amp;nbsp;may only&amp;nbsp;be converted to other pointer types (and to the integer type). In your case, try this:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;htype* handler;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;typedef struct&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;{&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp; char low;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp; char high;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;} SPLIT_T;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;const SPLIT_T* test_ptr = (SPLIT_T*)&amp;amp;handler;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;// test_ptr-&amp;gt;low points to&amp;nbsp;lower handler's address and test_ptr-&amp;gt;high points to higher part of address, assuming processor is running in low-endian mode.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Marc.&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 15 May 2006 21:17:44 GMT</pubDate>
    <dc:creator>marc_paquette</dc:creator>
    <dc:date>2006-05-15T21:17:44Z</dc:date>
    <item>
      <title>type casting in CW12 V3.1</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/type-casting-in-CW12-V3-1/m-p/135838#M1779</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hi,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;I have the question on typecasting mechanism&amp;nbsp;:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;The simple code is below (small memory model):&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;typedef struct&lt;/DIV&gt;&lt;DIV&gt;{&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;char low;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;char high;&lt;/DIV&gt;&lt;DIV&gt;}SPLIT_T;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;const unsigned char test_ch = (unsigned char )&amp;amp;handler; // Does not work ...storage dest is too small. I understand and would expect that test_ch would contain either msb or lsb of the handler's address!?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;const SPLIT_T test_split = (SPLIT_T )&amp;amp;handler; // Compiler complaines - illegal typecast ????&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;void handler(void);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;void main(void)&lt;/DIV&gt;&lt;DIV&gt;{&lt;/DIV&gt;&lt;DIV&gt;...&lt;/DIV&gt;&lt;DIV&gt;}&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;void handler(void)&lt;/DIV&gt;&lt;DIV&gt;{&lt;/DIV&gt;&lt;DIV&gt;...&lt;/DIV&gt;&lt;DIV&gt;}&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Any ideas...&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Regards, Mark&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 13 May 2006 03:10:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/type-casting-in-CW12-V3-1/m-p/135838#M1779</guid>
      <dc:creator>markiscarabas</dc:creator>
      <dc:date>2006-05-13T03:10:29Z</dc:date>
    </item>
    <item>
      <title>Re: type casting in CW12 V3.1</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/type-casting-in-CW12-V3-1/m-p/135839#M1780</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Pointer types&amp;nbsp;may only&amp;nbsp;be converted to other pointer types (and to the integer type). In your case, try this:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;htype* handler;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;typedef struct&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;{&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp; char low;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp; char high;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;} SPLIT_T;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;const SPLIT_T* test_ptr = (SPLIT_T*)&amp;amp;handler;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;// test_ptr-&amp;gt;low points to&amp;nbsp;lower handler's address and test_ptr-&amp;gt;high points to higher part of address, assuming processor is running in low-endian mode.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Marc.&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 May 2006 21:17:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/type-casting-in-CW12-V3-1/m-p/135839#M1780</guid>
      <dc:creator>marc_paquette</dc:creator>
      <dc:date>2006-05-15T21:17:44Z</dc:date>
    </item>
    <item>
      <title>Re: type casting in CW12 V3.1</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/type-casting-in-CW12-V3-1/m-p/135840#M1781</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;The name "handler" is to be regarded as a function pointer. So there is no need to take the address of it. This should work:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;typedef struct&lt;BR /&gt;{&lt;BR /&gt;char low;&lt;BR /&gt;char high;&lt;BR /&gt;}SPLIT_T;&lt;BR /&gt;&lt;BR /&gt;void handler (void);&lt;BR /&gt;&lt;BR /&gt;const SPLIT_T test_split = *(SPLIT_T*)handler;&lt;BR /&gt;&lt;BR /&gt;And as mentioned, which part of the address that ends up where depends on little/big endian.&lt;BR /&gt;&lt;BR /&gt;Since you seem to be using HC12 with big endian, you should swap the order of low/high.&lt;BR /&gt;&lt;BR /&gt;On HC12, you also need to be careful with where you place "handler" in the memory. If you place it in banked flash, it would suddenly become a 3-byte "far" pointer where the ms byte is the flash page.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 May 2006 20:16:14 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/type-casting-in-CW12-V3-1/m-p/135840#M1781</guid>
      <dc:creator>Lundin</dc:creator>
      <dc:date>2006-05-18T20:16:14Z</dc:date>
    </item>
  </channel>
</rss>

