<?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[reinterpret_cast versteh ich noch nicht ganz]]></title><description><![CDATA[<p>Das mit dem reinterpret_cast verstehe ich immer noch nicht ganz, bei folgendem, Beispiel:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;
using namespace std;

int main()
{
    int value=122;
    double X=12.36444;
    int *p1=&amp;value;

    return 0;
}
</code></pre>
<p>kommt eine Warnung. Weil ich ja den Wert von einem &quot;double&quot; in eine &quot;int&quot; Variable reinhaue. Okay, also habe ich mir gedacht wende ich hier einen &quot;reinterpret_cast&quot; an (weil es handelt sich ja um einen Zeiger), sodass ich die Warnung weg bekomme.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;
using namespace std;

int main()
{
    int value=122;
    double X=12.36444;
    int *p1=&amp;value;
    *p1=reinterpret_cast&lt;int*&gt;(X);

    return 0;
}
</code></pre>
<p>Aber das geht nicht, das kommt die Fehlermeldung hier:</p>
<blockquote>
<p>Compiling: C:\MinGW\Andi\casts.cpp<br />
C:\MinGW\Andi\casts.cpp: In function <code>int main()': C:\\MinGW\\Andi\\casts.cpp:13: error: invalid reinterpret_cast from type \</code>double' to type `int*'<br />
Process terminated with status 1 (0 minutes, 0 seconds)<br />
1 errors, 0 warnings</p>
</blockquote>
<p>Mh was mach ich falsch? Ist das der falsche cast? Der einzige cast der mit einfallen würde, der passen könnte wäre &quot;static_cast&quot;, aber den wende ich ja nur an, wenn ich von double nach int konvertiere, bei NICHT Zeiger Variablen.!?<br />
Mh, kann mir jemand helfen?</p>
<p>MfG<br />
Stromberg</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/200967/reinterpret_cast-versteh-ich-noch-nicht-ganz</link><generator>RSS for Node</generator><lastBuildDate>Mon, 05 Oct 2026 06:05:29 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/200967.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 22 Dec 2007 11:51:21 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to reinterpret_cast versteh ich noch nicht ganz on Sat, 22 Dec 2007 11:51:21 GMT]]></title><description><![CDATA[<p>Das mit dem reinterpret_cast verstehe ich immer noch nicht ganz, bei folgendem, Beispiel:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;
using namespace std;

int main()
{
    int value=122;
    double X=12.36444;
    int *p1=&amp;value;

    return 0;
}
</code></pre>
<p>kommt eine Warnung. Weil ich ja den Wert von einem &quot;double&quot; in eine &quot;int&quot; Variable reinhaue. Okay, also habe ich mir gedacht wende ich hier einen &quot;reinterpret_cast&quot; an (weil es handelt sich ja um einen Zeiger), sodass ich die Warnung weg bekomme.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;
using namespace std;

int main()
{
    int value=122;
    double X=12.36444;
    int *p1=&amp;value;
    *p1=reinterpret_cast&lt;int*&gt;(X);

    return 0;
}
</code></pre>
<p>Aber das geht nicht, das kommt die Fehlermeldung hier:</p>
<blockquote>
<p>Compiling: C:\MinGW\Andi\casts.cpp<br />
C:\MinGW\Andi\casts.cpp: In function <code>int main()': C:\\MinGW\\Andi\\casts.cpp:13: error: invalid reinterpret_cast from type \</code>double' to type `int*'<br />
Process terminated with status 1 (0 minutes, 0 seconds)<br />
1 errors, 0 warnings</p>
</blockquote>
<p>Mh was mach ich falsch? Ist das der falsche cast? Der einzige cast der mit einfallen würde, der passen könnte wäre &quot;static_cast&quot;, aber den wende ich ja nur an, wenn ich von double nach int konvertiere, bei NICHT Zeiger Variablen.!?<br />
Mh, kann mir jemand helfen?</p>
<p>MfG<br />
Stromberg</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1424764</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1424764</guid><dc:creator><![CDATA[Stromberg]]></dc:creator><pubDate>Sat, 22 Dec 2007 11:51:21 GMT</pubDate></item><item><title><![CDATA[Reply to reinterpret_cast versteh ich noch nicht ganz on Sat, 22 Dec 2007 12:08:08 GMT]]></title><description><![CDATA[<p><strong>Achtung Halbwissen</strong></p>
<p>Du willst, dass ein int-Zeiger auf einen double-Wert zeigt. Das geht nicht...</p>
<p>MfG</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1424767</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1424767</guid><dc:creator><![CDATA[ceplusplus@loggedoff]]></dc:creator><pubDate>Sat, 22 Dec 2007 12:08:08 GMT</pubDate></item><item><title><![CDATA[Reply to reinterpret_cast versteh ich noch nicht ganz on Sat, 22 Dec 2007 12:11:02 GMT]]></title><description><![CDATA[<p>Was willst du eigentlich erreichen? Gehen würde z.B.</p>
<pre><code class="language-cpp">int* p = reinterpret_cast&lt;int*&gt;(&amp;X);
</code></pre>
<p>, aber ob das das ist, was du willst, weiß ich nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1424768</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1424768</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Sat, 22 Dec 2007 12:11:02 GMT</pubDate></item><item><title><![CDATA[Reply to reinterpret_cast versteh ich noch nicht ganz on Sat, 22 Dec 2007 12:38:10 GMT]]></title><description><![CDATA[<p>Gut, dann ahb ichs falsch verstanden. Jetzt weiß ich wies geht, ich wollte genau das hier erreichen:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;
using namespace std;

int main()
{
    int value=992;
    double X=12.36444;
    int *p1=&amp;value;
    *p1=static_cast&lt;int&gt;(X);
    cout &lt;&lt; value &lt;&lt; endl;

    return 0;
}
</code></pre>
<p>Der Variable &quot;value&quot; über den Zeiger p1 den Wert von der double-Variable X übergeben, ohne das mein Compiler eine Warnung ausspuckt!</p>
<p>MfG<br />
Stromberg</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1424777</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1424777</guid><dc:creator><![CDATA[Stromberg]]></dc:creator><pubDate>Sat, 22 Dec 2007 12:38:10 GMT</pubDate></item></channel></rss>