<?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[Struktur größer als Inhalt?]]></title><description><![CDATA[<p>Hi,</p>
<p>mir ist eben etwas sehr interessantes aufgefallen wo ich absolut keinen Peil sehe, warum das so ist.</p>
<p>Also: Ich habe eine Struktur mit dem Namen 'item'. In ihr sind zwei char-Arrays der Breite von 13 und 9, und ein long (Größe 4 Byte).</p>
<p>Das ergibt bei meinem Kopfrechnen eine größe von 26 Byte. Denkste!</p>
<p>Hab ein Programm geschrieben um mich selbst zu überzeugen und versteh den Sinn dahinter nicht <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

struct item
{
    char name[13];
    long size;
    char buffer[9];
};

#define showSize(x) std::cout &lt;&lt; #x &lt;&lt; &quot; : &quot; &lt;&lt; sizeof(x) &lt;&lt; std::endl;

int main (void)
{
    item temp;

    showSize(temp.name);
    showSize(temp.size);
    showSize(temp.buffer);

    std::cout &lt;&lt; &quot;Total: &quot; &lt;&lt; sizeof(temp.name) +
                              sizeof(temp.size) +
                              sizeof(temp.buffer) &lt;&lt; std::endl &lt;&lt; std::endl;

    std::cout &lt;&lt; &quot;---&quot; &lt;&lt; std::endl;

    showSize(item);
    showSize(temp);

    std::cin.get ();

    return 0;
}
</code></pre>
<p>Ausgabe:<br />
<a href="http://temp.name" rel="nofollow">temp.name</a> : 13<br />
temp.size : 4<br />
temp.buffer : 9<br />
Total: 26<br />
---<br />
item : 32<br />
temp : 32</p>
<p>WARUM ist die Struktur nicht 26 groß sondern 32?? Und wie kann ich es hinbekommen das die Struktur 26 Byte groß ist?</p>
<p>p.s.: Ich benutze Visual C++ Express</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/131164/struktur-größer-als-inhalt</link><generator>RSS for Node</generator><lastBuildDate>Thu, 27 Aug 2026 01:02:32 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/131164.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 31 Dec 2005 17:13:14 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Struktur größer als Inhalt? on Sat, 31 Dec 2005 17:13:14 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>mir ist eben etwas sehr interessantes aufgefallen wo ich absolut keinen Peil sehe, warum das so ist.</p>
<p>Also: Ich habe eine Struktur mit dem Namen 'item'. In ihr sind zwei char-Arrays der Breite von 13 und 9, und ein long (Größe 4 Byte).</p>
<p>Das ergibt bei meinem Kopfrechnen eine größe von 26 Byte. Denkste!</p>
<p>Hab ein Programm geschrieben um mich selbst zu überzeugen und versteh den Sinn dahinter nicht <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

struct item
{
    char name[13];
    long size;
    char buffer[9];
};

#define showSize(x) std::cout &lt;&lt; #x &lt;&lt; &quot; : &quot; &lt;&lt; sizeof(x) &lt;&lt; std::endl;

int main (void)
{
    item temp;

    showSize(temp.name);
    showSize(temp.size);
    showSize(temp.buffer);

    std::cout &lt;&lt; &quot;Total: &quot; &lt;&lt; sizeof(temp.name) +
                              sizeof(temp.size) +
                              sizeof(temp.buffer) &lt;&lt; std::endl &lt;&lt; std::endl;

    std::cout &lt;&lt; &quot;---&quot; &lt;&lt; std::endl;

    showSize(item);
    showSize(temp);

    std::cin.get ();

    return 0;
}
</code></pre>
<p>Ausgabe:<br />
<a href="http://temp.name" rel="nofollow">temp.name</a> : 13<br />
temp.size : 4<br />
temp.buffer : 9<br />
Total: 26<br />
---<br />
item : 32<br />
temp : 32</p>
<p>WARUM ist die Struktur nicht 26 groß sondern 32?? Und wie kann ich es hinbekommen das die Struktur 26 Byte groß ist?</p>
<p>p.s.: Ich benutze Visual C++ Express</p>
]]></description><link>https://www.c-plusplus.net/forum/post/953589</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/953589</guid><dc:creator><![CDATA[&#x27;#&#x27;]]></dc:creator><pubDate>Sat, 31 Dec 2005 17:13:14 GMT</pubDate></item><item><title><![CDATA[Reply to Struktur größer als Inhalt? on Sat, 31 Dec 2005 17:16:10 GMT]]></title><description><![CDATA[<p>Damit der Prozessor schneller auf die Elemente zugreifen kann.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/953595</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/953595</guid><dc:creator><![CDATA[hmmmmmmmmmmm]]></dc:creator><pubDate>Sat, 31 Dec 2005 17:16:10 GMT</pubDate></item><item><title><![CDATA[Reply to Struktur größer als Inhalt? on Sat, 31 Dec 2005 17:18:49 GMT]]></title><description><![CDATA[<p>hmmmmmmmmmmm schrieb:</p>
<blockquote>
<p>Damit der Prozessor schneller auf die Elemente zugreifen kann.</p>
</blockquote>
<p>Reseviert er 6 Byte für??</p>
]]></description><link>https://www.c-plusplus.net/forum/post/953597</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/953597</guid><dc:creator><![CDATA[joomoo]]></dc:creator><pubDate>Sat, 31 Dec 2005 17:18:49 GMT</pubDate></item><item><title><![CDATA[Reply to Struktur größer als Inhalt? on Sat, 31 Dec 2005 17:19:51 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">struct item
{
    char name[13]; // &lt;- 16
    long size; // &lt;- 4 
    char buffer[9]; // &lt;- 12
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/953598</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/953598</guid><dc:creator><![CDATA[...........]]></dc:creator><pubDate>Sat, 31 Dec 2005 17:19:51 GMT</pubDate></item><item><title><![CDATA[Reply to Struktur größer als Inhalt? on Sat, 31 Dec 2005 17:21:34 GMT]]></title><description><![CDATA[<p>Schau mal nach dem Stichwort &quot;Alignment&quot; in der ForumSuche/Google in dem zusammenhang. Danach kann z.B. ein char nicht ein byte beanspruchen, sondern plötlich 4, damit der prozessor auf die folgende variable schneller zugreifen kann... <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/953599</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/953599</guid><dc:creator><![CDATA[OnlyFoo-Silvester]]></dc:creator><pubDate>Sat, 31 Dec 2005 17:21:34 GMT</pubDate></item><item><title><![CDATA[Reply to Struktur größer als Inhalt? on Sat, 31 Dec 2005 17:27:03 GMT]]></title><description><![CDATA[<p>@OnlyFoo-Silvester<br />
kann man denn die struktur auf diese größe ausrichten? mir geht es ja nicht um speed <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/953604</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/953604</guid><dc:creator><![CDATA[&#x27;#&#x27;]]></dc:creator><pubDate>Sat, 31 Dec 2005 17:27:03 GMT</pubDate></item><item><title><![CDATA[Reply to Struktur größer als Inhalt? on Sat, 31 Dec 2005 17:28:24 GMT]]></title><description><![CDATA[<p>Nicht mit Standard C++ sondern mit Compiler-Optionen oder speziellen Anweisungen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/953606</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/953606</guid><dc:creator><![CDATA[align]]></dc:creator><pubDate>Sat, 31 Dec 2005 17:28:24 GMT</pubDate></item><item><title><![CDATA[Reply to Struktur größer als Inhalt? on Sat, 31 Dec 2005 17:28:38 GMT]]></title><description><![CDATA[<p>Kannst in den Einstellungen normalerweise das Alignment deaktivieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/953607</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/953607</guid><dc:creator><![CDATA[User---]]></dc:creator><pubDate>Sat, 31 Dec 2005 17:28:38 GMT</pubDate></item></channel></rss>