<?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 Struct members memory order in 8-bit Microcontrollers</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Struct-members-memory-order/m-p/159920#M9547</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;Hi,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial;"&gt;Is there a way to tell the linker to place&amp;nbsp;struct members in memory in the order they where defined in the code? This will place the struct members in consecutive order as written in the struct definition.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial;"&gt;The reason for this is to use the memcpy function to copy an entire memory segment ("as is") into the struct.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial;"&gt;Thanks,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial;"&gt;S.B.D&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 09 Mar 2009 23:23:54 GMT</pubDate>
    <dc:creator>S_B_D</dc:creator>
    <dc:date>2009-03-09T23:23:54Z</dc:date>
    <item>
      <title>Struct members memory order</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Struct-members-memory-order/m-p/159920#M9547</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;Hi,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial;"&gt;Is there a way to tell the linker to place&amp;nbsp;struct members in memory in the order they where defined in the code? This will place the struct members in consecutive order as written in the struct definition.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial;"&gt;The reason for this is to use the memcpy function to copy an entire memory segment ("as is") into the struct.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial;"&gt;Thanks,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial;"&gt;S.B.D&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Mar 2009 23:23:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Struct-members-memory-order/m-p/159920#M9547</guid>
      <dc:creator>S_B_D</dc:creator>
      <dc:date>2009-03-09T23:23:54Z</dc:date>
    </item>
    <item>
      <title>Re: Struct members memory order</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Struct-members-memory-order/m-p/159921#M9548</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As far as I could check structure fields are allocated in the sequence they are defined.&lt;/P&gt;&lt;P&gt;- Which CPU are you targeting (HC08, HC12, Coldfire, ..)&lt;BR /&gt;- Which version of CodeWarrior are you using?&lt;BR /&gt;To retrieve that info:&lt;BR /&gt;- Start CodeWarrior&lt;BR /&gt;- Select Help -&amp;gt; About Freescale CodeWarrior&lt;BR /&gt;- Click on "Install Products"&lt;BR /&gt;- CodeWarrior version used is displayed on top in the Installed Products dialog.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Additionally how is the structure defined?&lt;/P&gt;&lt;P&gt;CrasyCat&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Mar 2009 23:44:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Struct-members-memory-order/m-p/159921#M9548</guid>
      <dc:creator>CrasyCat</dc:creator>
      <dc:date>2009-03-09T23:44:21Z</dc:date>
    </item>
    <item>
      <title>Re: Struct members memory order</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Struct-members-memory-order/m-p/159922#M9549</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the reply CrasyCat.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm working on the MC9S08JM32 on Code-Warrior 5.9.0 build 2830.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you will see the&amp;nbsp;structure is not aligned:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;typedef struct{&lt;BR /&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;unsigned char &amp;nbsp;Misc;&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;&lt;/P&gt;&lt;P&gt;unsigned int&amp;nbsp;&amp;nbsp; ConnectedSensors[8];&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;unsigned char&amp;nbsp;&amp;nbsp; Timer1Prescaler;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;unsigned int&amp;nbsp;&amp;nbsp; Timer1AuxCounter;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;unsigned int&amp;nbsp;&amp;nbsp; Timer1Modulo;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;unsigned char&amp;nbsp;&amp;nbsp; NumberOfSamplesInPacket;&lt;BR /&gt;unsigned int&amp;nbsp;&amp;nbsp; NumberOfSamplesInPacketToPc;&lt;BR /&gt;unsigned char &amp;nbsp;PcRate;&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;&lt;BR /&gt;unsigned int&amp;nbsp;&amp;nbsp; TriggerLevelHigh;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;unsigned int&amp;nbsp;&amp;nbsp;&amp;nbsp; TriggerLevelLow;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;unsigned char&amp;nbsp;&amp;nbsp; TriggerType_Input;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;unsigned int&amp;nbsp;&amp;nbsp; Calibration[8];&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;unsigned char&amp;nbsp;&amp;nbsp; Timing[4];&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;}Status;&lt;BR /&gt;extern Status STATUS, *STATUSptr;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;S.B.D&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Mar 2009 00:06:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Struct-members-memory-order/m-p/159922#M9549</guid>
      <dc:creator>S_B_D</dc:creator>
      <dc:date>2009-03-10T00:06:03Z</dc:date>
    </item>
    <item>
      <title>Re: Struct members memory order</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Struct-members-memory-order/m-p/159923#M9550</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;ANSI C requires that struct members are allocated in the declaration order, why do you think this is not happening here?&lt;/P&gt;&lt;P&gt;For copying structs, memcpy should work however just assigning structs is even easier.&lt;/P&gt;&lt;P&gt;Also not sure what your comment about alignment is about, alignment is a different issue than the order which fields are allocated. For a 8 bit chip as a S08, there is usually no alignment padding added by the compiler. In general, alignment is compiler specific and portable code should not rely on (the absence of) alignment.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Mar 2009 00:47:25 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Struct-members-memory-order/m-p/159923#M9550</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2009-03-10T00:47:25Z</dc:date>
    </item>
  </channel>
</rss>

