<?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 HC12: char and short in an union? in CodeWarrior for MCU</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC12-char-and-short-in-an-union/m-p/143220#M3023</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Message Edited by CrasyCat on &lt;SPAN class="date_text"&gt;2007-04-13&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;11:04 AM&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 20 Jan 2007 02:59:31 GMT</pubDate>
    <dc:creator>Pang</dc:creator>
    <dc:date>2007-01-20T02:59:31Z</dc:date>
    <item>
      <title>HC12: char and short in an union?</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC12-char-and-short-in-an-union/m-p/143220#M3023</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Message Edited by CrasyCat on &lt;SPAN class="date_text"&gt;2007-04-13&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;11:04 AM&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 20 Jan 2007 02:59:31 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC12-char-and-short-in-an-union/m-p/143220#M3023</guid>
      <dc:creator>Pang</dc:creator>
      <dc:date>2007-01-20T02:59:31Z</dc:date>
    </item>
    <item>
      <title>Re: char and short in an union?</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC12-char-and-short-in-an-union/m-p/143221#M3024</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;What processor are you targeting? It appears that the compiler is generating big-endian code.&lt;BR /&gt;&lt;BR /&gt;This setup will give you the behavior you're looking for:&lt;BR /&gt;&lt;BR /&gt;#include &amp;lt;assert.h&amp;gt;&lt;BR /&gt;&lt;BR /&gt;typedef struct twochars&lt;BR /&gt;{&lt;BR /&gt;/* Assumes big-endian. */&lt;BR /&gt;/* Reverse order of hi and lo for little-endian. */&lt;BR /&gt; char hi; &lt;BR /&gt; char lo;&lt;BR /&gt;} twochars;&lt;BR /&gt;&lt;BR /&gt;union DATA&lt;BR /&gt;{&lt;BR /&gt; twochars chData;&lt;BR /&gt; unsigned short shData;&lt;BR /&gt;} data;&lt;BR /&gt;&lt;BR /&gt;data.chData.lo = 8;&lt;BR /&gt;assert(data.shData == data.chData.lo);&lt;BR /&gt;&lt;BR /&gt;Marc.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 20 Jan 2007 05:10:33 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC12-char-and-short-in-an-union/m-p/143221#M3024</guid>
      <dc:creator>marc_paquette</dc:creator>
      <dc:date>2007-01-20T05:10:33Z</dc:date>
    </item>
    <item>
      <title>Re: char and short in an union?</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC12-char-and-short-in-an-union/m-p/143222#M3025</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Marc,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks for your prompt reply. My target process will be MC9S12XDP512. I will try your method.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I just tried the same code in Visual C++, both chData and shData have the same value at the first byte. So the Intel kingdom is different from the Motorola world&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Does the compiler have&amp;nbsp;an options to change that? Any way, I doubt it.&amp;nbsp; I do remember when I use LDD $1000 in HC11 language, the data in 0x1000 will be put in A and 0x1001 will be in B.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Pang&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 20 Jan 2007 07:23:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC12-char-and-short-in-an-union/m-p/143222#M3025</guid>
      <dc:creator>Pang</dc:creator>
      <dc:date>2007-01-20T07:23:27Z</dc:date>
    </item>
    <item>
      <title>Re: char and short in an union?</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC12-char-and-short-in-an-union/m-p/143223#M3026</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Pang wrote:&lt;BR /&gt;&amp;gt;&amp;gt; Does the compiler have an options to change that?&lt;BR /&gt;&lt;BR /&gt;You could change the byte order at compile time by using platform dependent, pre-defined constants of the compilers.&lt;BR /&gt;For example:&lt;BR /&gt;&lt;BR /&gt;typedef struct twochars&lt;BR /&gt;{&lt;BR /&gt;#if defined (__HIWARE__) // big endian&lt;BR /&gt;char hi;&lt;BR /&gt;char lo;&lt;BR /&gt;#elif defined (WIN32) // brain damaged 'intel' byte order&lt;BR /&gt;char lo;&lt;BR /&gt;char hi;&lt;BR /&gt;#endif&lt;BR /&gt;} twochars;&lt;BR /&gt;&lt;BR /&gt;..but it's generally not a good idea to access parts of a variable by mixing structs into a union. Compilers might insert alignment and padding bytes into structures. Better use shifts an bit-operations. It is much more portable.&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;-&amp;gt; pittbull&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 21 Jan 2007 01:28:53 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC12-char-and-short-in-an-union/m-p/143223#M3026</guid>
      <dc:creator>pittbull</dc:creator>
      <dc:date>2007-01-21T01:28:53Z</dc:date>
    </item>
    <item>
      <title>Re: char and short in an union?</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC12-char-and-short-in-an-union/m-p/143224#M3027</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Hello Pang,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Yet another possibility is for the union to use a two byte array.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;union DATA&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;{&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;unsigned char chData[2];&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;unsigned short shData;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;} data;&amp;nbsp;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;You can then individually assign a value to either byte.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&amp;nbsp;&amp;nbsp;&lt;FONT face="Courier New"&gt;data.ChData[1] = 8;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Regards,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Mac&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Jan 2007 04:28:31 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC12-char-and-short-in-an-union/m-p/143224#M3027</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2007-01-22T04:28:31Z</dc:date>
    </item>
    <item>
      <title>Re: char and short in an union?</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC12-char-and-short-in-an-union/m-p/143225#M3028</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;No, the CodeWarrior compiler does not have an option to change endianness for the HC(S)08 &amp;amp; HC(S)12 targets because these targets are big-endian exclusively. Other Freescale products have configurable endianness, like the Power Architecture processors for example.&lt;BR /&gt;&lt;BR /&gt;To handle endianness in a processor-independent manner, you'll have to manipulate data programmatically and not rely on processor/compiler behaviors.&lt;BR /&gt;&lt;BR /&gt;Marc.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Jan 2007 02:31:19 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC12-char-and-short-in-an-union/m-p/143225#M3028</guid>
      <dc:creator>marc_paquette</dc:creator>
      <dc:date>2007-01-23T02:31:19Z</dc:date>
    </item>
  </channel>
</rss>

