<?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 definition for ColdFires / Codewarrior in ColdFire/68K Microcontrollers and Processors</title>
    <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/struct-definition-for-ColdFires-Codewarrior/m-p/133183#M1228</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="font-family: Arial; font-size: 2;"&gt;I cannot&amp;nbsp;create correctly a structure with odd number of bytes, for example, a struct containing a longint(32b) and a char(8b) &amp;nbsp;should result a 5 bytes size right?Or a shortint(16b) &amp;nbsp;and a char(8b)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="font-family: Arial; font-size: 2;"&gt;should result a 3 bytes size..&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="font-family: Arial; font-size: 2;"&gt;Codewarrior generates a 6 bytes size and 4 bytes size, respectivelly...&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="font-family: Arial; font-size: 2;"&gt;For only chars member it works, but if I mix int/long etc...booo..&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="font-family: Arial; font-size: 2;"&gt;Couls someone help me?&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="font-family: Arial; font-size: 2;"&gt;Ricardo Raupp&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 16 Oct 2006 02:07:25 GMT</pubDate>
    <dc:creator>Ricardo_RauppV</dc:creator>
    <dc:date>2006-10-16T02:07:25Z</dc:date>
    <item>
      <title>struct definition for ColdFires / Codewarrior</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/struct-definition-for-ColdFires-Codewarrior/m-p/133183#M1228</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="font-family: Arial; font-size: 2;"&gt;I cannot&amp;nbsp;create correctly a structure with odd number of bytes, for example, a struct containing a longint(32b) and a char(8b) &amp;nbsp;should result a 5 bytes size right?Or a shortint(16b) &amp;nbsp;and a char(8b)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="font-family: Arial; font-size: 2;"&gt;should result a 3 bytes size..&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="font-family: Arial; font-size: 2;"&gt;Codewarrior generates a 6 bytes size and 4 bytes size, respectivelly...&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="font-family: Arial; font-size: 2;"&gt;For only chars member it works, but if I mix int/long etc...booo..&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="font-family: Arial; font-size: 2;"&gt;Couls someone help me?&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="font-family: Arial; font-size: 2;"&gt;Ricardo Raupp&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Oct 2006 02:07:25 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/struct-definition-for-ColdFires-Codewarrior/m-p/133183#M1228</guid>
      <dc:creator>Ricardo_RauppV</dc:creator>
      <dc:date>2006-10-16T02:07:25Z</dc:date>
    </item>
    <item>
      <title>Re: struct definition for ColdFires / Codewarrior</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/struct-definition-for-ColdFires-Codewarrior/m-p/133184#M1229</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;hello,&lt;BR /&gt;&lt;BR /&gt;This behavior is normal for the ColdFire family, all datas access are aligned as the operand size.&lt;BR /&gt;So a short int have to be aligned on even addresses, and long int have to be aligned on modulo 4 addresses.&lt;BR /&gt;The compiler warns you, when it adds a padding byte.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Emmanuel&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Oct 2006 18:40:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/struct-definition-for-ColdFires-Codewarrior/m-p/133184#M1229</guid>
      <dc:creator>Nouchi</dc:creator>
      <dc:date>2006-10-16T18:40:48Z</dc:date>
    </item>
    <item>
      <title>Re: struct definition for ColdFires / Codewarrior</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/struct-definition-for-ColdFires-Codewarrior/m-p/133185#M1230</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hello,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;If you want byte aligment,&amp;nbsp;include the following pragma :&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;#pragma options align=packed&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;Bye&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Oct 2006 14:45:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/struct-definition-for-ColdFires-Codewarrior/m-p/133185#M1230</guid>
      <dc:creator>Arev</dc:creator>
      <dc:date>2006-10-17T14:45:34Z</dc:date>
    </item>
    <item>
      <title>Re: struct definition for ColdFires / Codewarrior</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/struct-definition-for-ColdFires-Codewarrior/m-p/133186#M1231</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Hi Folks.....specially Arev ...:&lt;IMG alt=":smileyhappy:" class="emoticon emoticon-smileyhappy" id="smileyhappy" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-happy.gif" title="Smiley Happy" /&gt;&lt;IMG alt=":smileyhappy:" class="emoticon emoticon-smileyhappy" id="smileyhappy" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-happy.gif" title="Smiley Happy" /&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Yesterday I received a tip from a guy (Chris - the Nop Head...) from wildrice forum with a clue for it.&lt;/DIV&gt;&lt;DIV&gt;I spent&amp;nbsp;yesterday to test it in order to check if besides the size I hoped it is used as it shoud be.&lt;/DIV&gt;&lt;DIV&gt;Well ..it is working !!&lt;/DIV&gt;&lt;DIV&gt;Now I can create any struct size/format I want.&lt;/DIV&gt;&lt;DIV&gt;The solution he gave me is exactly the one Arev showed...&lt;/DIV&gt;&lt;DIV&gt;that is .. :&lt;/DIV&gt;&lt;DIV&gt;#pragma options align=packed&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;In order to add info to this issue (maybe usefull for other people), follow bellow the Chris comment about it, wich culminated to Arev´s &amp;nbsp;&amp;nbsp;clue.&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;Very Thanks everybody !!!!!::&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Hi Ricardo,&lt;BR /&gt;&amp;nbsp;I am not a Codewarrior expert having only used it for a few days but according to the documentation for the verson I have to hand it only supports #pragma pack on x86 and MIPS targets but it does have:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#pragma options align=packed&lt;BR /&gt;which comes with the description "Aligns every field on a 1-byte boundary. It is not available in any panel. This alignment causes your code to crash or run slowly on many platforms. &lt;EM&gt;Use it with caution"&lt;/EM&gt;.&lt;BR /&gt;&lt;BR /&gt;You can use:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#pragma options align=reset&lt;BR /&gt;to restore normal aligment.&lt;BR /&gt;&lt;BR /&gt;There is also a "Struct Alignment" option on the "Target Setting Panel / Code Generation / ColdFire Processor" dialog but that only supports 68K (which will be 16 bit alignment) and 68K 4-byte. If you are using a 32 bit data bus you should set it to "68K 4-byte" to get maximum speed performance. If want smallest memory usage or have a 16 bit data bus you should set it to 68K. You can then use the pragmas around specific structure definitions to force them to be packed. You will get a speed reduction if you have 32 bit values that are not aligned on multiples of the data bus size.&lt;BR /&gt;&lt;BR /&gt;Hope this helps, I have not tried it myself but I have done it with gcc and __attribute__ ((packed)).&lt;BR /&gt;&lt;BR /&gt;Regards, Chris&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Oct 2006 21:04:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/struct-definition-for-ColdFires-Codewarrior/m-p/133186#M1231</guid>
      <dc:creator>Ricardo_RauppV</dc:creator>
      <dc:date>2006-10-17T21:04:23Z</dc:date>
    </item>
    <item>
      <title>Re: struct definition for ColdFires / Codewarrior</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/struct-definition-for-ColdFires-Codewarrior/m-p/133187#M1232</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;More info I received from Wildrice forum&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;Peter Barada wrote:&lt;BR /&gt;&amp;gt;&amp;gt;I tested it by checking its size , behavior , etc..and it is OK ...&lt;BR /&gt;&amp;gt;&amp;gt;Now I can create any kind of structure...it's very&lt;BR /&gt;&amp;gt;&amp;gt;confortable...specially if you have already applications made based on&lt;BR /&gt;&amp;gt;&amp;gt;structures ..&lt;BR /&gt;&amp;gt;&lt;BR /&gt;&amp;gt;Remember that you're making a trade here.&amp;nbsp; Since the "#pragma packed"&lt;BR /&gt;&amp;gt;tells the compiler to ignore the alignment of bothe the structuer, and&lt;BR /&gt;&amp;gt;its members, then any access to a member requires that it is loaded&lt;BR /&gt;&amp;gt;into registers using bytes, so if you have an int, the compiler will&lt;BR /&gt;&amp;gt;emit four byte loads as well as three shifts to load the value.&amp;nbsp; The&lt;BR /&gt;&amp;gt;same for a store.&amp;nbsp; This can dramatically increase both the size of the&lt;BR /&gt;&amp;gt;code, as well as the execution time.&lt;BR /&gt;&amp;gt;&lt;BR /&gt;&amp;gt;As an example, gcc-3.4.3 compiles the following code for -m5307:&lt;BR /&gt;&amp;gt;&lt;BR /&gt;&amp;gt;struct foo {&lt;BR /&gt;&amp;gt;&amp;nbsp;&amp;nbsp;int x;&lt;BR /&gt;&amp;gt;&amp;nbsp;&amp;nbsp;char y;&lt;BR /&gt;&amp;gt;} __attribute__ ((packed));&lt;BR /&gt;&amp;gt;&lt;BR /&gt;&amp;gt;int bar(struct foo *p)&lt;BR /&gt;&amp;gt;{&lt;BR /&gt;&amp;gt;&amp;nbsp;&amp;nbsp;return p-&amp;gt;x;&lt;BR /&gt;&amp;gt;}&lt;BR /&gt;&amp;gt;&lt;BR /&gt;&amp;gt;Into (removing the fuction prologue/epilogue code):&lt;BR /&gt;&amp;gt;&lt;BR /&gt;&amp;gt;move.b (%a0),%d1&lt;BR /&gt;&amp;gt;moveq #24,%d0&lt;BR /&gt;&amp;gt;lsl.l %d0,%d1&lt;BR /&gt;&amp;gt;move.b 1(%a0),%d0&lt;BR /&gt;&amp;gt;swap %d0&lt;BR /&gt;&amp;gt;clr.w %d0&lt;BR /&gt;&amp;gt;and.l #16711680,%d0&lt;BR /&gt;&amp;gt;or.l %d1,%d0&lt;BR /&gt;&amp;gt;move.b 2(%a0),%d1&lt;BR /&gt;&amp;gt;lsl.l #8,%d1&lt;BR /&gt;&amp;gt;and.l #65280,%d1&lt;BR /&gt;&amp;gt;or.l %d0,%d1&lt;BR /&gt;&amp;gt;clr.l %d0&lt;BR /&gt;&amp;gt;move.b 3(%a0),%d0&lt;BR /&gt;&amp;gt;or.l %d1,%d0&lt;BR /&gt;&amp;gt;&lt;BR /&gt;&amp;gt;So to access member 'x' from the 'foo' structure whose address is in %a0,&lt;BR /&gt;&amp;gt;leaving it in %d0 while using %d1 as a temporary takes 15 instructions&lt;BR /&gt;&amp;gt;consuming 48 bytes instead of one instruction that consumes 2 bytes,&lt;BR /&gt;&amp;gt;or 15 times as slow, and 24 times as big.&lt;BR /&gt;&amp;gt;&lt;BR /&gt;&amp;gt;Just some food for thought.&lt;BR /&gt;&amp;gt;&lt;BR /&gt;&lt;BR /&gt;While that is something you don't want normally, it's very nice that gcc&lt;BR /&gt;will make the correct code when you *do* need it.&amp;nbsp; Occasionally you meet&lt;BR /&gt;a structure that is defined externally and doesn't fit the proper&lt;BR /&gt;alignments, making the "packed" attribute very handy.&amp;nbsp; If only there&lt;BR /&gt;also was a "little-endian" attribute (Diab Data's compiler has that&lt;BR /&gt;feature, IIRC).&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;and ...&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;You are right. But sometimes you have to live with it. For example, accessing SCSI structures or FAT12/FAT16/FAT32 structures from your application requires the struct fields not to be aligned.   &lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;PRE&gt;&lt;!--    --&gt;True, but one possiblity is to extract from the unaligned struct theinformation you need just once, and the refer to that information viaaligned variables.  This can reduce both execution time *and* codespace... &lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;For small pieces of code, yes. But try to write a full file system this way...&lt;BR /&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Oct 2006 18:51:42 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/struct-definition-for-ColdFires-Codewarrior/m-p/133187#M1232</guid>
      <dc:creator>Ricardo_RauppV</dc:creator>
      <dc:date>2006-10-18T18:51:42Z</dc:date>
    </item>
  </channel>
</rss>

