<?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>LPCXpresso IDE FAQsのトピックPacked Structures</title>
    <link>https://community.nxp.com/t5/LPCXpresso-IDE-FAQs/Packed-Structures/m-p/473585#M104</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;By default, GCC does not pack structures so it will in general leave spaces so that data items are word aligned. This behavior can be changed by using the "packed" attribute on the structure.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="color: #646464; font-family: Arial, sans-serif; font-size: 12px; padding: 5px 10px; background: #eeeeee;"&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 12pt;"&gt;&lt;STRONG&gt;&lt;TT&gt;struct foo&lt;BR /&gt;{&amp;nbsp; short a;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; char b;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; int c;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; char d;&lt;BR /&gt;} __attribute__((packed));&lt;/TT&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Some other toolchains have alternative ways of packing structures. For example a particular toolchain might use a qualifier "&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;TT&gt;__packed&lt;/TT&gt;&lt;/SPAN&gt;" which needs to be placed before the structure rather than using an attribute after the structure. The following code snippet shows how code might be written to allow the code to be compilable using either toolchain...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="color: #646464; font-family: Arial, sans-serif; font-size: 12px; padding: 5px 10px; background: #eeeeee;"&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 12pt;"&gt;&lt;STRONG&gt;&lt;TT&gt;#if defined(__GNUC__)&amp;nbsp;&amp;nbsp; // LPCXpresso Tools&lt;BR /&gt;&amp;nbsp; #define PRE_PACK&lt;BR /&gt;&amp;nbsp; #define POST_PACK&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; __attribute__((packed))&lt;BR /&gt;#else&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; // Other toolchain&lt;BR /&gt;&amp;nbsp; #define PRE_PACK&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; __packed&lt;BR /&gt;&amp;nbsp; #define POST_PACK&lt;BR /&gt;#endif&lt;/TT&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="color: #646464; font-family: Arial, sans-serif; font-size: 12px; padding: 5px 10px; background: #eeeeee;"&gt;&lt;SPAN style="font-size: 12pt;"&gt;---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="color: #646464; font-family: Arial, sans-serif; font-size: 12px; padding: 5px 10px; background: #eeeeee;"&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 12pt;"&gt;&lt;STRONG&gt;&lt;TT&gt;PRE_PACK struct foo&lt;BR /&gt;{&amp;nbsp; short a;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; char b;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; int c;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; char d;&lt;BR /&gt;} POST_PACK ;&lt;/TT&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Note:&lt;/STRONG&gt; packing data can have code size and performance overheads so is not recommended for general use. However there are some circumstances where you may need to make use of it - for example for accessing data coming in from peripherals.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;H1&gt;#pragma pack&lt;/H1&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For compatibility with certain other toolchains GCC also offers a pragma which can be used to control the packing of structures.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For more details see the GCC documentation: &lt;A href="https://gcc.gnu.org/onlinedocs/gcc/Structure-Layout-Pragmas.html"&gt;Structure-Packing Pragmas&lt;/A&gt;​&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 31 Mar 2016 22:34:00 GMT</pubDate>
    <dc:creator>lpcware-support</dc:creator>
    <dc:date>2016-03-31T22:34:00Z</dc:date>
    <item>
      <title>Packed Structures</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE-FAQs/Packed-Structures/m-p/473585#M104</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;By default, GCC does not pack structures so it will in general leave spaces so that data items are word aligned. This behavior can be changed by using the "packed" attribute on the structure.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="color: #646464; font-family: Arial, sans-serif; font-size: 12px; padding: 5px 10px; background: #eeeeee;"&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 12pt;"&gt;&lt;STRONG&gt;&lt;TT&gt;struct foo&lt;BR /&gt;{&amp;nbsp; short a;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; char b;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; int c;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; char d;&lt;BR /&gt;} __attribute__((packed));&lt;/TT&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Some other toolchains have alternative ways of packing structures. For example a particular toolchain might use a qualifier "&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;TT&gt;__packed&lt;/TT&gt;&lt;/SPAN&gt;" which needs to be placed before the structure rather than using an attribute after the structure. The following code snippet shows how code might be written to allow the code to be compilable using either toolchain...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="color: #646464; font-family: Arial, sans-serif; font-size: 12px; padding: 5px 10px; background: #eeeeee;"&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 12pt;"&gt;&lt;STRONG&gt;&lt;TT&gt;#if defined(__GNUC__)&amp;nbsp;&amp;nbsp; // LPCXpresso Tools&lt;BR /&gt;&amp;nbsp; #define PRE_PACK&lt;BR /&gt;&amp;nbsp; #define POST_PACK&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; __attribute__((packed))&lt;BR /&gt;#else&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; // Other toolchain&lt;BR /&gt;&amp;nbsp; #define PRE_PACK&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; __packed&lt;BR /&gt;&amp;nbsp; #define POST_PACK&lt;BR /&gt;#endif&lt;/TT&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="color: #646464; font-family: Arial, sans-serif; font-size: 12px; padding: 5px 10px; background: #eeeeee;"&gt;&lt;SPAN style="font-size: 12pt;"&gt;---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="color: #646464; font-family: Arial, sans-serif; font-size: 12px; padding: 5px 10px; background: #eeeeee;"&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 12pt;"&gt;&lt;STRONG&gt;&lt;TT&gt;PRE_PACK struct foo&lt;BR /&gt;{&amp;nbsp; short a;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; char b;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; int c;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; char d;&lt;BR /&gt;} POST_PACK ;&lt;/TT&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Note:&lt;/STRONG&gt; packing data can have code size and performance overheads so is not recommended for general use. However there are some circumstances where you may need to make use of it - for example for accessing data coming in from peripherals.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;H1&gt;#pragma pack&lt;/H1&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For compatibility with certain other toolchains GCC also offers a pragma which can be used to control the packing of structures.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For more details see the GCC documentation: &lt;A href="https://gcc.gnu.org/onlinedocs/gcc/Structure-Layout-Pragmas.html"&gt;Structure-Packing Pragmas&lt;/A&gt;​&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 Mar 2016 22:34:00 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE-FAQs/Packed-Structures/m-p/473585#M104</guid>
      <dc:creator>lpcware-support</dc:creator>
      <dc:date>2016-03-31T22:34:00Z</dc:date>
    </item>
  </channel>
</rss>

