<?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[#pragma pack will nicht richtig]]></title><description><![CDATA[<p>Hi,</p>
<p>irgendwie geht #pragma pack bei mir nicht so richtig, weiß jemand wo der fehler liegt?</p>
<pre><code class="language-cpp">#include &lt;stdio.h&gt;
#include &lt;conio.h&gt;

#pragma pack (push)
struct struct1
{
    unsigned short f : 6;
    unsigned short b : 6;
    unsigned short c : 1;
    unsigned short r : 3;
};
#pragma pack (pop)

struct struct2
{
    unsigned short f : 6;
    unsigned short b : 6;
    unsigned short c : 1;
    unsigned short r : 3;
};

int main (void)
{
    printf (&quot;%d\n&quot;, sizeof (struct1));          // soll 2 ausgeben, gibt 2 aus
    printf (&quot;%d\n&quot;, sizeof (struct2));          // soll 4 ausgeben, gibt 2 aus
    printf (&quot;%d\n&quot;, sizeof (unsigned short));   // soll 2 ausgeben, gibt 2 aus
    _getch ();
    return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/237500/pragma-pack-will-nicht-richtig</link><generator>RSS for Node</generator><lastBuildDate>Wed, 23 Sep 2026 10:01:20 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/237500.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 29 Mar 2009 19:45:46 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to #pragma pack will nicht richtig on Sun, 29 Mar 2009 19:45:46 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>irgendwie geht #pragma pack bei mir nicht so richtig, weiß jemand wo der fehler liegt?</p>
<pre><code class="language-cpp">#include &lt;stdio.h&gt;
#include &lt;conio.h&gt;

#pragma pack (push)
struct struct1
{
    unsigned short f : 6;
    unsigned short b : 6;
    unsigned short c : 1;
    unsigned short r : 3;
};
#pragma pack (pop)

struct struct2
{
    unsigned short f : 6;
    unsigned short b : 6;
    unsigned short c : 1;
    unsigned short r : 3;
};

int main (void)
{
    printf (&quot;%d\n&quot;, sizeof (struct1));          // soll 2 ausgeben, gibt 2 aus
    printf (&quot;%d\n&quot;, sizeof (struct2));          // soll 4 ausgeben, gibt 2 aus
    printf (&quot;%d\n&quot;, sizeof (unsigned short));   // soll 2 ausgeben, gibt 2 aus
    _getch ();
    return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1687964</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1687964</guid><dc:creator><![CDATA[fenriswolf]]></dc:creator><pubDate>Sun, 29 Mar 2009 19:45:46 GMT</pubDate></item><item><title><![CDATA[Reply to #pragma pack will nicht richtig on Sun, 29 Mar 2009 19:56:16 GMT]]></title><description><![CDATA[<p>fenriswolf schrieb:</p>
<blockquote>
<p>Hi,</p>
<p>irgendwie geht #pragma pack bei mir nicht so richtig, weiß jemand wo der fehler liegt?</p>
<pre><code class="language-cpp">printf (&quot;%d\n&quot;, sizeof (struct2));          // soll 4 ausgeben, gibt 2 aus
</code></pre>
</blockquote>
<p>Verstehe nicht, wo liegt das Problem? 2 Byte Größe sehen doch völlig richtig aus.<br />
Normalerweise wird pragma pack auch eher für sowas verwendet:</p>
<pre><code class="language-cpp">// Mit Packen ist's 5 Bytes groß, sonst 8 Bytes.
struct A
{
    int a;
    char c;
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1687966</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1687966</guid><dc:creator><![CDATA[Badestrand]]></dc:creator><pubDate>Sun, 29 Mar 2009 19:56:16 GMT</pubDate></item><item><title><![CDATA[Reply to #pragma pack will nicht richtig on Sun, 29 Mar 2009 20:39:04 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;stdio.h&gt;
#include &lt;conio.h&gt;

#pragma pack (push)
#pragma pack(1) // &lt;!--- boing
struct struct1
{
    unsigned short f : 6;
    unsigned short b : 6;
    unsigned short c : 1;
    unsigned short r : 3;
};
#pragma pack (pop)
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1687978</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1687978</guid><dc:creator><![CDATA[___________]]></dc:creator><pubDate>Sun, 29 Mar 2009 20:39:04 GMT</pubDate></item></channel></rss>