<?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: Structure alignment problem in Cosmic cross compiler for MC9S12DP256 in S12 / MagniV Microcontrollers</title>
    <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Structure-alignment-problem-in-Cosmic-cross-compiler-for/m-p/137211#M2510</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Hello Rathinavel,&lt;BR /&gt;&lt;BR /&gt;compiling your code yields a struct size if 202 as you expected.&lt;BR /&gt;&lt;BR /&gt;I suggest to ask Cosmic directly or post your question again in the mailing list [1] where Cosmic reads also.&lt;BR /&gt;&lt;BR /&gt;Oliver&lt;BR /&gt;&lt;BR /&gt;[1] &lt;A href="http://groups.yahoo.com/group/68HC12/" target="test_blank"&gt;http://groups.yahoo.com/group/68HC12/&lt;/A&gt; - you don't need a Yahoo! account, send a blank mail to the subscription address.&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 29 May 2006 14:05:55 GMT</pubDate>
    <dc:creator>Obetz</dc:creator>
    <dc:date>2006-05-29T14:05:55Z</dc:date>
    <item>
      <title>Structure alignment problem in Cosmic cross compiler for MC9S12DP256</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Structure-alignment-problem-in-Cosmic-cross-compiler-for/m-p/137209#M2508</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hello All,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I am using Cosmic C compiler for MC9S12DP256 (16 bit microcontroller)&amp;nbsp; in my project.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I am facing the following problem&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;typedef struct {&lt;/DIV&gt;&lt;DIV&gt;unsigned char&amp;nbsp;Var1[182];&amp;nbsp; // 182 bytes&lt;/DIV&gt;&lt;DIV&gt;unsigned long&amp;nbsp; Var2;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // 4 bytes&lt;/DIV&gt;&lt;DIV&gt;unsigned char Var3[16];&amp;nbsp;&amp;nbsp; // 16 bytes&lt;/DIV&gt;&lt;DIV&gt;}ABC;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;As you see here this structure should take 202 bytes of memory , but when i use sizeof(ABC) --&amp;gt; it returns 204&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;my doubt is, even though the elements in this structure is align to even position, why the compiler is padding 2 more bytes extra?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks and regards - Rathinavel&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 27 May 2006 14:08:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Structure-alignment-problem-in-Cosmic-cross-compiler-for/m-p/137209#M2508</guid>
      <dc:creator>Rathnam</dc:creator>
      <dc:date>2006-05-27T14:08:44Z</dc:date>
    </item>
    <item>
      <title>Re: Structure alignment problem in Cosmic cross compiler for MC9S12DP256</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Structure-alignment-problem-in-Cosmic-cross-compiler-for/m-p/137210#M2509</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;P&gt;Hi Rathinavel&lt;/P&gt;&lt;P&gt;Presumably the compiler is putting var2 to start at an aligned long word boundary and so skipping 2 bytes at the end of the Var1 array. Normally there will be a compiler setting allowing you to define whether long words are aligned to such boundaries.&lt;/P&gt;&lt;P&gt;If the exact ordering of the variables in the struture is not critical you could also put the long word variable to the top of the structure so that it is started at an aligned address and the bytes of the following arrays will not have to be aligned. This is a general programming tip for processors where the alignment is fixed and can not be controlled by the compiler - start structures, local variables etc. in the order largest first und finish with smallest (bytes) so that the compiler can make the best of the memory space without unnecessary holes.&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Mark Butcher&lt;BR /&gt;&lt;A href="http://www.mjbc.ch" rel="nofollow" target="_blank"&gt;www.mjbc.ch&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 27 May 2006 16:53:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Structure-alignment-problem-in-Cosmic-cross-compiler-for/m-p/137210#M2509</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2006-05-27T16:53:07Z</dc:date>
    </item>
    <item>
      <title>Re: Structure alignment problem in Cosmic cross compiler for MC9S12DP256</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Structure-alignment-problem-in-Cosmic-cross-compiler-for/m-p/137211#M2510</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Hello Rathinavel,&lt;BR /&gt;&lt;BR /&gt;compiling your code yields a struct size if 202 as you expected.&lt;BR /&gt;&lt;BR /&gt;I suggest to ask Cosmic directly or post your question again in the mailing list [1] where Cosmic reads also.&lt;BR /&gt;&lt;BR /&gt;Oliver&lt;BR /&gt;&lt;BR /&gt;[1] &lt;A href="http://groups.yahoo.com/group/68HC12/" target="test_blank"&gt;http://groups.yahoo.com/group/68HC12/&lt;/A&gt; - you don't need a Yahoo! account, send a blank mail to the subscription address.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 May 2006 14:05:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Structure-alignment-problem-in-Cosmic-cross-compiler-for/m-p/137211#M2510</guid>
      <dc:creator>Obetz</dc:creator>
      <dc:date>2006-05-29T14:05:55Z</dc:date>
    </item>
  </channel>
</rss>

