<?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[Zeiger Cast - Verständnis Frage]]></title><description><![CDATA[<p>Kann mir jemand folgenden Code erklären? Insbesondere Zeile 10.</p>
<pre><code class="language-cpp">struct TESTSTRUCT
{
	int test;
};

//...

void Test(void *testptr)
{
	TESTSTRUCT *teststr = reinterpret_cast&lt;TESTSTRUCT *&gt;(testptr);

	//...
	//...
}
</code></pre>
<p>Was genau bewirkt diese Zeile? Zeigt teststr jetzt auf testptr oder wird die Adresse übernommen? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/309416/zeiger-cast-verständnis-frage</link><generator>RSS for Node</generator><lastBuildDate>Wed, 05 Aug 2026 06:30:41 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/309416.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 22 Oct 2012 19:15:56 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Zeiger Cast - Verständnis Frage on Mon, 22 Oct 2012 19:15:56 GMT]]></title><description><![CDATA[<p>Kann mir jemand folgenden Code erklären? Insbesondere Zeile 10.</p>
<pre><code class="language-cpp">struct TESTSTRUCT
{
	int test;
};

//...

void Test(void *testptr)
{
	TESTSTRUCT *teststr = reinterpret_cast&lt;TESTSTRUCT *&gt;(testptr);

	//...
	//...
}
</code></pre>
<p>Was genau bewirkt diese Zeile? Zeigt teststr jetzt auf testptr oder wird die Adresse übernommen? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2262986</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2262986</guid><dc:creator><![CDATA[ptrcast]]></dc:creator><pubDate>Mon, 22 Oct 2012 19:15:56 GMT</pubDate></item><item><title><![CDATA[Reply to Zeiger Cast - Verständnis Frage on Mon, 22 Oct 2012 19:30:13 GMT]]></title><description><![CDATA[<p>teststr zeigt auf das Objekt hinter testptr. Du sagst dem Compiler, dass du jetzt einen Zeiger vom Typ TESTSTRUCT haben möchtest und kannst dann das hier machen:</p>
<pre><code class="language-cpp">std::cout &lt;&lt; teststr-&gt;test;
</code></pre>
<p>Das geht mit testptr z.B. nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2262991</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2262991</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Mon, 22 Oct 2012 19:30:13 GMT</pubDate></item><item><title><![CDATA[Reply to Zeiger Cast - Verständnis Frage on Mon, 22 Oct 2012 19:31:43 GMT]]></title><description><![CDATA[<p>Es wird lediglich der Typ des Zeigers von <code>void*</code> in <code>TESTSTRUCT*</code> gecastet. Wobei fraglich ist, wieso genau da mit <code>void*</code> gearbeitet wird, in C++ sollte das relativ selten nötig sein. Abgesehen davon, wäre ein <code>static_cast</code> ausreichend...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2262992</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2262992</guid><dc:creator><![CDATA[dot]]></dc:creator><pubDate>Mon, 22 Oct 2012 19:31:43 GMT</pubDate></item><item><title><![CDATA[Reply to Zeiger Cast - Verständnis Frage on Mon, 22 Oct 2012 20:12:04 GMT]]></title><description><![CDATA[<p>Casts von und zu void * sind ein wenig heikel, da sie nicht wissen, welches Objekt sich dahinter verbirgt, und du für die Richtigkeit des Casts zuständig bist. Der Compiler bekommt u.U. auch nicht mit, dass du krumme Sachen in deinem Code schreibst. Dereferenzieren kannst du sie sowieso nicht.</p>
<p>Edit: Stroustrup schrieb mal dazu</p>
<blockquote>
<p>Functions using void* pointers typically exist at the very lowest level of the system, where real hardware resources are manipulated.<br />
Occurrences of void* at higher levels of the system should be viewed with suspicion because they are likely indicators of design errors.</p>
</blockquote>
<p>Ich würde versuchen solche Typumwandlungen meiden, wenn es nur möglich ist. Man sollte sich auf jeden Fall überlegen, ob Funktionsüberladungen, Templates, smart pointers, etc. nicht eine bessere Alternative für den Ansatz sind.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2263000</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2263000</guid><dc:creator><![CDATA[*Rewind*]]></dc:creator><pubDate>Mon, 22 Oct 2012 20:12:04 GMT</pubDate></item></channel></rss>