<?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[verkettete liste innerhalb char-array]]></title><description><![CDATA[<p>Hallo,</p>
<p>zur Übung will ich einen Speicherpool schreiben, dazu alloziere ich eine Menge an Speicher über ein char-Array. Das char-Array wird in gleich große Blöcke unterteilt, die dann verkettet werden.<br />
Ich schreibe also in den ersten Block die Adresse des nächsten Blocks.</p>
<p>Folgender Code funktioniert abern nicht wie erwartet:</p>
<pre><code>int main()
{
   char mem[16];

   *(reinterpret_cast&lt;void**&gt;(mem)) = reinterpret_cast&lt;void*&gt;(mem+sizeof(void*));

   std::cout &lt;&lt; reinterpret_cast&lt;void*&gt;(mem) &lt;&lt; &quot;\n&quot;;
   std::cout &lt;&lt; reinterpret_cast&lt;void*&gt;(*mem) &lt;&lt; &quot;\n&quot;;

}
</code></pre>
<p>Ausgabe entweder in der Form:</p>
<pre><code>0x7fff43cbf1c0
0xffffffffffffffc8
</code></pre>
<p>oder</p>
<pre><code>0x7fff2a8c0230
0x38
</code></pre>
<p>ich erwarte aber:</p>
<pre><code>0x7fff2a8c0230
0x7fff2a8c0238
</code></pre>
<p>Wenn ich mir von gdb direkt den Speicherinhalt ausgeben lasse (8B) bekomme ich:</p>
<pre><code>(gdb) x/1xg 0x7fffffffe060
0x7fffffffe060:	0x00007fffffffe068
</code></pre>
<p>Also siehts im Debugger richtig aus...</p>
<p>Wo liegt mein Fehler?<br />
Danke schonmal im Voraus.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/324107/verkettete-liste-innerhalb-char-array</link><generator>RSS for Node</generator><lastBuildDate>Tue, 14 Jul 2026 20:26:51 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/324107.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 03 Mar 2014 13:12:33 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to verkettete liste innerhalb char-array on Mon, 03 Mar 2014 13:12:33 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>zur Übung will ich einen Speicherpool schreiben, dazu alloziere ich eine Menge an Speicher über ein char-Array. Das char-Array wird in gleich große Blöcke unterteilt, die dann verkettet werden.<br />
Ich schreibe also in den ersten Block die Adresse des nächsten Blocks.</p>
<p>Folgender Code funktioniert abern nicht wie erwartet:</p>
<pre><code>int main()
{
   char mem[16];

   *(reinterpret_cast&lt;void**&gt;(mem)) = reinterpret_cast&lt;void*&gt;(mem+sizeof(void*));

   std::cout &lt;&lt; reinterpret_cast&lt;void*&gt;(mem) &lt;&lt; &quot;\n&quot;;
   std::cout &lt;&lt; reinterpret_cast&lt;void*&gt;(*mem) &lt;&lt; &quot;\n&quot;;

}
</code></pre>
<p>Ausgabe entweder in der Form:</p>
<pre><code>0x7fff43cbf1c0
0xffffffffffffffc8
</code></pre>
<p>oder</p>
<pre><code>0x7fff2a8c0230
0x38
</code></pre>
<p>ich erwarte aber:</p>
<pre><code>0x7fff2a8c0230
0x7fff2a8c0238
</code></pre>
<p>Wenn ich mir von gdb direkt den Speicherinhalt ausgeben lasse (8B) bekomme ich:</p>
<pre><code>(gdb) x/1xg 0x7fffffffe060
0x7fffffffe060:	0x00007fffffffe068
</code></pre>
<p>Also siehts im Debugger richtig aus...</p>
<p>Wo liegt mein Fehler?<br />
Danke schonmal im Voraus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2386286</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2386286</guid><dc:creator><![CDATA[mortified_penguin]]></dc:creator><pubDate>Mon, 03 Mar 2014 13:12:33 GMT</pubDate></item><item><title><![CDATA[Reply to verkettete liste innerhalb char-array on Mon, 03 Mar 2014 13:16:38 GMT]]></title><description><![CDATA[<p>(*mem) ist doch ein char.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2386287</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2386287</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Mon, 03 Mar 2014 13:16:38 GMT</pubDate></item><item><title><![CDATA[Reply to verkettete liste innerhalb char-array on Mon, 03 Mar 2014 14:08:44 GMT]]></title><description><![CDATA[<p>Achso, also anstatt die 8 Bytes als Pointer zu interpretieren wird nur das erste Byte als Pointer interpretiert?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2386299</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2386299</guid><dc:creator><![CDATA[mortified_penguin]]></dc:creator><pubDate>Mon, 03 Mar 2014 14:08:44 GMT</pubDate></item></channel></rss>