<?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[Wann gelten 2 Typen als layout-kompatibel?]]></title><description><![CDATA[<p>Hallo liebe Community,</p>
<p>Ganz offesichtlich sind 2 Typen Layout-kompatibel, wenn sie gleich aufgebaut sind.</p>
<pre><code class="language-cpp">struct { int x; };
struct { int y; };
</code></pre>
<p>Wie siehts jedoch hier aus (Man vernachlaessige Alignment und Padding)?</p>
<pre><code class="language-cpp">struct { int x; };
struct { short y[2]; };
</code></pre>
<p>Oder diese beiden?</p>
<pre><code class="language-cpp">struct { int x; };
struct { void* p; };
</code></pre>
<p>Gilt das auch als Layout-kompatibel, vorrausgesetzt die Typen sind gleich alignt, haben die selbe Menge an Padding und 2 * sizeof(short) == sizeof(int) bzw. sizeof(int) == sizeof(void*)?</p>
<p>Gruessle,<br />
Der Kellerautomat</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/306850/wann-gelten-2-typen-als-layout-kompatibel</link><generator>RSS for Node</generator><lastBuildDate>Fri, 07 Aug 2026 04:39:13 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/306850.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 09 Aug 2012 05:35:01 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Wann gelten 2 Typen als layout-kompatibel? on Thu, 09 Aug 2012 05:35:53 GMT]]></title><description><![CDATA[<p>Hallo liebe Community,</p>
<p>Ganz offesichtlich sind 2 Typen Layout-kompatibel, wenn sie gleich aufgebaut sind.</p>
<pre><code class="language-cpp">struct { int x; };
struct { int y; };
</code></pre>
<p>Wie siehts jedoch hier aus (Man vernachlaessige Alignment und Padding)?</p>
<pre><code class="language-cpp">struct { int x; };
struct { short y[2]; };
</code></pre>
<p>Oder diese beiden?</p>
<pre><code class="language-cpp">struct { int x; };
struct { void* p; };
</code></pre>
<p>Gilt das auch als Layout-kompatibel, vorrausgesetzt die Typen sind gleich alignt, haben die selbe Menge an Padding und 2 * sizeof(short) == sizeof(int) bzw. sizeof(int) == sizeof(void*)?</p>
<p>Gruessle,<br />
Der Kellerautomat</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2240280</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2240280</guid><dc:creator><![CDATA[Kellerautomat]]></dc:creator><pubDate>Thu, 09 Aug 2012 05:35:53 GMT</pubDate></item><item><title><![CDATA[Reply to Wann gelten 2 Typen als layout-kompatibel? on Thu, 09 Aug 2012 08:01:59 GMT]]></title><description><![CDATA[<p>Kellerautomat schrieb:</p>
<blockquote>
<p>Man vernachlaessige Alignment und Padding</p>
</blockquote>
<p>Sind ein Dreieck und ein Quadrat das Selbe, wenn man die Zahl der Ecken und die Winkel vernachlässigt? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>§9.2 schrieb:</p>
<blockquote>
<p>Two standard-layout struct (Clause 9) types are layout-compatible if they have the <strong>same number of non-static<br />
data members</strong> and <strong>corresponding non-static data members (in declaration order) have layout-compatible<br />
types (3.9)</strong></p>
</blockquote>
<p>§3.9 schrieb:</p>
<blockquote>
<p>If two types T1 and T2 are the <strong>same</strong> type, then T1 and T2 are layout-compatible types.</p>
</blockquote>
<p>Dass zwei Typen gleich groß sind, heißt nicht, dass sie <em>layout-compatible</em> sind. Ein Pointer und ein int haben außer der Größe, und dass beide <em>scalar-types</em> sind. Ein short[2] und ein int haben nichts gemeinsam, außer <em>unter Umständen</em> die gleiche Größe und dass beides <em>POD types</em> sind.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2240304</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2240304</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Thu, 09 Aug 2012 08:01:59 GMT</pubDate></item></channel></rss>