<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How to turn off fields alignment?]]></title><description><![CDATA[<p>How to make platform-independent way to turn off members and structures alignment in some piece of code?</p>
<p>In Visual Studio I use <code>#pragma pack(1)</code> before struct which needs to be packed, and <code>#pragma pack()</code> after it to restore original setting.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/213353/how-to-turn-off-fields-alignment</link><generator>RSS for Node</generator><lastBuildDate>Wed, 14 Oct 2026 07:21:36 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/213353.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 16 May 2008 18:32:52 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to turn off fields alignment? on Fri, 16 May 2008 18:32:52 GMT]]></title><description><![CDATA[<p>How to make platform-independent way to turn off members and structures alignment in some piece of code?</p>
<p>In Visual Studio I use <code>#pragma pack(1)</code> before struct which needs to be packed, and <code>#pragma pack()</code> after it to restore original setting.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1510714</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1510714</guid><dc:creator><![CDATA[SAn]]></dc:creator><pubDate>Fri, 16 May 2008 18:32:52 GMT</pubDate></item><item><title><![CDATA[Reply to How to turn off fields alignment? on Fri, 16 May 2008 18:57:18 GMT]]></title><description><![CDATA[<p>SAn schrieb:</p>
<blockquote>
<p>How to make platform-independent way to turn off members and structures alignment in some piece of code?</p>
<p>In Visual Studio I use <code>#pragma pack(1)</code> before struct which needs to be packed, and <code>#pragma pack()</code> after it to restore original setting.</p>
</blockquote>
<p>this depends on which compiler you plan to port your code for. with the gcc compiler you might specifiy alignment with the __attribute__ keyword:</p>
<pre><code class="language-cpp">struct foo
{
    int x[2] __attribute__ ((aligned(8)));
};
</code></pre>
<p>see: <a href="http://developer.apple.com/documentation/DeveloperTools/gcc-3.3/gcc/Variable-Attributes.html" rel="nofollow">linkage</a></p>
<p>to make code portable with msvc i see no other option than using the preprocessor directives:</p>
<pre><code class="language-cpp">#ifdef WIN32

#else

#endif
</code></pre>
<p>but i might miss other possibilities <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1510723</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1510723</guid><dc:creator><![CDATA[sothis_]]></dc:creator><pubDate>Fri, 16 May 2008 18:57:18 GMT</pubDate></item></channel></rss>