<?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: Problems using uint_16 in a structure in MQX Software Solutions</title>
    <link>https://community.nxp.com/t5/MQX-Software-Solutions/Problems-using-uint-16-in-a-structure/m-p/150968#M459</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I fear the union approach won't help because as soon as the union contains a long, the compiler will start to insert the align bytes as before.&lt;/P&gt;&lt;P&gt;The basic problem is that for your given layout the 4 byte int is not aligned for its type. Most 32 bit architecture compilers I'm aware of (not just CF) do align such a field by default. With a CF (and x86, for example) I'm sure there is a pragma to give you the desired layout. I guess something along the lines of a #pragma align (not sure).&lt;/P&gt;&lt;P&gt;Anyway, there are other architectures like PPC which won't allow the unaligned long.&lt;/P&gt;&lt;P&gt;So if you only want to support CF, search the pragma in the manual. If it matters to keep the code clean and easy to port for other architectures in the future I would go with the 2 byte only fields (or to explicitly fix the alignment with an additional 2 byte filler for all). That way you can keep the code clean and avoid CF specifics.&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;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 26 Sep 2010 05:10:51 GMT</pubDate>
    <dc:creator>CompilerGuru</dc:creator>
    <dc:date>2010-09-26T05:10:51Z</dc:date>
    <item>
      <title>Problems using uint_16 in a structure</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Problems-using-uint-16-in-a-structure/m-p/150963#M454</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey Folks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm having a problem specifying a 16 bit field in a structure.&amp;nbsp; When I declare:&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;FONT face="courier new,courier"&gt;&lt;FONT size="2"&gt;typedef&amp;nbsp;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT size="2"&gt;struct myfiles_def_struct {&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#7F0055"&gt;&lt;FONT color="#7F0055"&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P align="left"&gt;&amp;nbsp;&lt;/P&gt;&lt;P align="left"&gt;&lt;STRONG&gt;&lt;FONT color="#000000" face="courier new,courier" size="2"&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;STRONG&gt;&lt;FONT color="#000000" face="courier new,courier" size="2"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;// Block Header&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="courier new,courier" size="2"&gt;&amp;nbsp; &amp;nbsp; uint_16 FHDR;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="courier new,courier" size="2"&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="courier new,courier" size="2"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;// Size of data Block&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="courier new,courier" size="2"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;uint_32 FSIZE;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="courier new,courier" size="2"&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="courier new,courier" size="2"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;// 8 Character Block Identifier&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="courier new,courier" size="2"&gt;&amp;nbsp; &amp;nbsp; uint_8 FNAME[8];&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="courier new,courier" size="2"&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="courier new,courier" size="2"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;// Block Data/size specified by “FSIZE”&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;FONT color="#000000" face="courier new,courier" size="2"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;uint_8 FDATA[];&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;FONT color="#000000" face="courier new,courier" size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;FONT color="#000000" face="courier new,courier" size="2"&gt;} MYFILES_DEF_STRUCT, _PTR_ MYFILES_DEF_STRUCT_PTR;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the offset for "FSIZE" is 4 from&amp;nbsp;"FHDR" and not 2 like I would expect.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've searched the CW as well as the MQX forums for people who have found similar issues but with no luck.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas?&amp;nbsp; I feel like I'm missing something incredibly basic here.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanx,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;myke&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 25 Sep 2010 10:31:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Problems-using-uint-16-in-a-structure/m-p/150963#M454</guid>
      <dc:creator>mykepredko</dc:creator>
      <dc:date>2010-09-25T10:31:09Z</dc:date>
    </item>
    <item>
      <title>Problems using uint_16 in a structure - One more comment</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Problems-using-uint-16-in-a-structure/m-p/150964#M455</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry, I should have noted that "sizeof(MYFILES_DEF_STRUCT)" returns 16 and not 14 as expected.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanx,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;myke&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 25 Sep 2010 10:33:30 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Problems-using-uint-16-in-a-structure/m-p/150964#M455</guid>
      <dc:creator>mykepredko</dc:creator>
      <dc:date>2010-09-25T10:33:30Z</dc:date>
    </item>
    <item>
      <title>Re: Problems using uint_16 in a structure</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Problems-using-uint-16-in-a-structure/m-p/150965#M456</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It's the&amp;nbsp;uint_32 FSIZE field which gets aligned to its natural boundary. I usually try to align every field to its natural aligment to avoid compiler issues like this one. Probably there is a compiler pragma to control the alignment, if really necessary. Be careful to end the pragma's effect.&lt;/P&gt;&lt;P&gt;Is it strictly required that FSIZE starts at offset 2? One alternative would also be to splitup&amp;nbsp;FSIZE into 2 separate uint_16's.&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>Sat, 25 Sep 2010 12:00:24 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Problems-using-uint-16-in-a-structure/m-p/150965#M456</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2010-09-25T12:00:24Z</dc:date>
    </item>
    <item>
      <title>Re: Problems using uint_16 in a structure</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Problems-using-uint-16-in-a-structure/m-p/150966#M457</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;Thank you for the comments.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately, the data in this structure is being provided by another system and, along with this, there will be quite a few of these structures which is why the header was reduced to 16 bits and not 32 bits in the first place because the extra two bytes in each structure will become quite substantial.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There may be an opportunity to reverse FHDR and FSIZE when the data is generated for the ColdFire - this will mean that the data between the two systems will be no longer be the same (which could make for problems down the road).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm hoping to hear from the FSL guys regarding the boundaries and seeing if there is any opportunity there.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That's an interesting idea about breaking up the 32bit size field into two 16 bit - I'll try it and see how it works out.&amp;nbsp; In this case, I would be doing manually what the compiler should be doing automatically.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanx,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;myke&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 25 Sep 2010 20:45:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Problems-using-uint-16-in-a-structure/m-p/150966#M457</guid>
      <dc:creator>mykepredko</dc:creator>
      <dc:date>2010-09-25T20:45:09Z</dc:date>
    </item>
    <item>
      <title>Re: Problems using uint_16 in a structure</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Problems-using-uint-16-in-a-structure/m-p/150967#M458</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey Daniel,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just converted the 32bit FSIZE to a 16bit FSIZEHIGH and 16bit FSIZELOW.&amp;nbsp; The structure comes out as 14 bytes in size (which is correct) and the offsets are correct.&amp;nbsp; I could probably clean things up a bit more by making these two 16 bit values into a 32 bit union (I don't know if I'm that energetic right now).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm still interested in hearing what FSL comes back with regarding the original structure and if there is anything that they can suggest to allow its use.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanx again for the suggestion,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;myke&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 25 Sep 2010 21:33:26 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Problems-using-uint-16-in-a-structure/m-p/150967#M458</guid>
      <dc:creator>mykepredko</dc:creator>
      <dc:date>2010-09-25T21:33:26Z</dc:date>
    </item>
    <item>
      <title>Re: Problems using uint_16 in a structure</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Problems-using-uint-16-in-a-structure/m-p/150968#M459</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I fear the union approach won't help because as soon as the union contains a long, the compiler will start to insert the align bytes as before.&lt;/P&gt;&lt;P&gt;The basic problem is that for your given layout the 4 byte int is not aligned for its type. Most 32 bit architecture compilers I'm aware of (not just CF) do align such a field by default. With a CF (and x86, for example) I'm sure there is a pragma to give you the desired layout. I guess something along the lines of a #pragma align (not sure).&lt;/P&gt;&lt;P&gt;Anyway, there are other architectures like PPC which won't allow the unaligned long.&lt;/P&gt;&lt;P&gt;So if you only want to support CF, search the pragma in the manual. If it matters to keep the code clean and easy to port for other architectures in the future I would go with the 2 byte only fields (or to explicitly fix the alignment with an additional 2 byte filler for all). That way you can keep the code clean and avoid CF specifics.&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;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 26 Sep 2010 05:10:51 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Problems-using-uint-16-in-a-structure/m-p/150968#M459</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2010-09-26T05:10:51Z</dc:date>
    </item>
    <item>
      <title>Re: Problems using uint_16 in a structure</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Problems-using-uint-16-in-a-structure/m-p/150969#M460</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;I've come to the same conclusion as well.&amp;nbsp; The code isn't too ugly although it should probably be implemented using a macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't see the same behaviour with gcc (which is the compiler used to generate these structures in the first place on a WinPC), but its operation might be tailored to allow this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanx for the suggestion - things are moving forwards because if.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;myke&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 26 Sep 2010 05:15:56 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Problems-using-uint-16-in-a-structure/m-p/150969#M460</guid>
      <dc:creator>mykepredko</dc:creator>
      <dc:date>2010-09-26T05:15:56Z</dc:date>
    </item>
  </channel>
</rss>

