<?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[Int zu char Array]]></title><description><![CDATA[<p>Hallo,<br />
kennt wer denn Code um eine int Variable zu char Arrays zumachen?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/326893/int-zu-char-array</link><generator>RSS for Node</generator><lastBuildDate>Sat, 30 May 2026 22:15:35 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/326893.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 13 Jul 2014 09:56:27 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Int zu char Array on Sun, 13 Jul 2014 09:56:27 GMT]]></title><description><![CDATA[<p>Hallo,<br />
kennt wer denn Code um eine int Variable zu char Arrays zumachen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2408362</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2408362</guid><dc:creator><![CDATA[2WochenGesucht]]></dc:creator><pubDate>Sun, 13 Jul 2014 09:56:27 GMT</pubDate></item><item><title><![CDATA[Reply to Int zu char Array on Sun, 13 Jul 2014 10:19:01 GMT]]></title><description><![CDATA[<p>Falls du einen <code>int</code> in einen String schreiben willst: Dazu gibt es <a href="http://www.c-plusplus.net/forum/39488" rel="nofollow">hier einen FAQ-Eintrag</a>.</p>
<p>Der Beispielcode für C++11 ist</p>
<pre><code>// int -&gt; string 
  { 
    int const i = 10; 
    string s = to_string(i); 
    cout &lt;&lt; s &lt;&lt; endl; 
  }
</code></pre>
<p>Ansonsten musst du dich etwas klarer ausdrücken, deine Frage ist ziemlich mehrdeutig.</p>
<p>Edit: Da du ja explizit nach** <code>char</code> -Arrays** fragst: Mittels der Methode<a href="http://en.cppreference.com/w/cpp/string/basic_string/c_str" rel="nofollow"> <code>c_str()</code> </a>bekommt man einen nullterminierten C-String welcher den gleichen Inhalt hat wie das <code>string</code> -Objekt.</p>
<p>Falls du ein modifizierbares <code>char</code> -Array haben willst, kannst du auch das <code>&amp;str[0]</code> -Idiom verwenden. Und falls du tatsächlich ein echtes <code>char</code> -Array<strong>objekt</strong> brauchst, definiere selbiges und nutze<a href="http://en.cppreference.com/w/cpp/io/c/fprintf" rel="nofollow"> <code>snprintf</code> </a>um die Zahl hineinzuschreiben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2408364</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2408364</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Sun, 13 Jul 2014 10:19:01 GMT</pubDate></item><item><title><![CDATA[Reply to Int zu char Array on Sun, 13 Jul 2014 10:15:49 GMT]]></title><description><![CDATA[<p>ich glaube er hat z.b. ein 32 bit integer und will daraus ein char[4] machen um z.b. die einzelnen bytewerte zu verarbeiten... Jedenfalls würde ich das draus interpretieren</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2408365</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2408365</guid><dc:creator><![CDATA[interpreta]]></dc:creator><pubDate>Sun, 13 Jul 2014 10:15:49 GMT</pubDate></item><item><title><![CDATA[Reply to Int zu char Array on Sun, 13 Jul 2014 10:27:37 GMT]]></title><description><![CDATA[<p>Genau das meine ich</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2408366</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2408366</guid><dc:creator><![CDATA[2WochenGesucht]]></dc:creator><pubDate>Sun, 13 Jul 2014 10:27:37 GMT</pubDate></item><item><title><![CDATA[Reply to Int zu char Array on Sun, 13 Jul 2014 10:35:46 GMT]]></title><description><![CDATA[<p>interpreta schrieb:</p>
<blockquote>
<p>ich glaube er hat z.b. ein 32 bit integer und will daraus ein char[4] machen um z.b. die einzelnen bytewerte zu verarbeiten... Jedenfalls würde ich das draus interpretieren</p>
</blockquote>
<p><code>memcpy</code> dürfte reichen:</p>
<pre><code>int i = 2234;

	unsigned char arr[sizeof(int)];

	std::memcpy(arr, &amp;i, sizeof(arr)); // benötigt &lt;cstring&gt;
</code></pre>
<p>Natürlich ist es auch möglich Bitshifts zu verwenden:</p>
<pre><code>int i = 2234;

	unsigned char arr[sizeof(int)];

	// Die Schleife wird vom Compiler geunrolled.
	for( unsigned c = 0; c != sizeof(arr); ++c )
		arr[c] = i &gt;&gt; c*CHAR_BIT; // benötigt &lt;climits&gt;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2408368</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2408368</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Sun, 13 Jul 2014 10:35:46 GMT</pubDate></item><item><title><![CDATA[Reply to Int zu char Array on Sun, 13 Jul 2014 16:13:17 GMT]]></title><description><![CDATA[<p>Oder einfach casten und direkt auf dem Original arbeiten?</p>
<pre><code>int foo = 7;
	reinterpret_cast&lt;char*&gt;(&amp;foo)[0]=9;
	cout &lt;&lt; foo;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2408395</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2408395</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Sun, 13 Jul 2014 16:13:17 GMT</pubDate></item><item><title><![CDATA[Reply to Int zu char Array on Sun, 13 Jul 2014 18:23:07 GMT]]></title><description><![CDATA[<p>Ich schließe die Frage gleich mal an:<br />
Union böse oder gangbar?</p>
<pre><code>template &lt;typename T&gt; // hier evtl nur fundamentaltypen zulassen
union Serializer
{
    T value;
    char [sizeof(T)] data;
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2408419</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2408419</guid><dc:creator><![CDATA[5cript]]></dc:creator><pubDate>Sun, 13 Jul 2014 18:23:07 GMT</pubDate></item><item><title><![CDATA[Reply to Int zu char Array on Sun, 13 Jul 2014 18:30:19 GMT]]></title><description><![CDATA[<p>Tim06TR schrieb:</p>
<blockquote>
<p>Ich schließe die Frage gleich mal an:<br />
Union böse oder gangbar?</p>
</blockquote>
<p>Ein Klugscheißer würde einwenden, dass es undefiniertes Verhalten ist. Ich würde daraufhin einwenden, dass es in jeder bekannten Implementierung wie gewünscht funktioniert und daher eine gute Methode ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2408420</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2408420</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Sun, 13 Jul 2014 18:30:19 GMT</pubDate></item><item><title><![CDATA[Reply to Int zu char Array on Sun, 13 Jul 2014 18:50:49 GMT]]></title><description><![CDATA[<p>SeppJ schrieb:</p>
<blockquote>
<p>Oder einfach casten und direkt auf dem Original arbeiten?</p>
<pre><code>int foo = 7;
	reinterpret_cast&lt;char*&gt;(&amp;foo)[0]=9;
	cout &lt;&lt; foo;
</code></pre>
</blockquote>
<p>Das versteh ich nicht ganz... warum [0]=9?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2408424</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2408424</guid><dc:creator><![CDATA[interpreta]]></dc:creator><pubDate>Sun, 13 Jul 2014 18:50:49 GMT</pubDate></item><item><title><![CDATA[Reply to Int zu char Array on Sun, 13 Jul 2014 18:57:50 GMT]]></title><description><![CDATA[<p>Warum nicht? Ist doch nur ein Beispiel.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2408425</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2408425</guid><dc:creator><![CDATA[Jodocus]]></dc:creator><pubDate>Sun, 13 Jul 2014 18:57:50 GMT</pubDate></item><item><title><![CDATA[Reply to Int zu char Array on Mon, 14 Jul 2014 08:58:18 GMT]]></title><description><![CDATA[<blockquote>
<p>Ein Klugscheißer würde einwenden, dass es undefiniertes Verhalten ist.</p>
</blockquote>
<p>Warum?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2408455</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2408455</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Mon, 14 Jul 2014 08:58:18 GMT</pubDate></item><item><title><![CDATA[Reply to Int zu char Array on Mon, 14 Jul 2014 09:51:18 GMT]]></title><description><![CDATA[<p>Arcoth schrieb:</p>
<blockquote>
<blockquote>
<p>Ein Klugscheißer würde einwenden, dass es undefiniertes Verhalten ist.</p>
</blockquote>
<p>Warum?</p>
</blockquote>
<p>Wenn ich das nicht falsch verstanden habe, dann dürfte das 9.5.1 sein:</p>
<p>§9.5.1 schrieb:</p>
<blockquote>
<p>In a union, at most one of the non-static data members can be active at any time, that is, the value of at most one of the non-static data members can be stored in a union at any time.</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/2408467</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2408467</guid><dc:creator><![CDATA[Fytch]]></dc:creator><pubDate>Mon, 14 Jul 2014 09:51:18 GMT</pubDate></item><item><title><![CDATA[Reply to Int zu char Array on Mon, 14 Jul 2014 09:55:35 GMT]]></title><description><![CDATA[<p>Übersetzt also in etwa:<br />
In einem Union darf nur auf das zuletzt beschriebene Member lesend zugegriffen werden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2408470</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2408470</guid><dc:creator><![CDATA[Th69]]></dc:creator><pubDate>Mon, 14 Jul 2014 09:55:35 GMT</pubDate></item><item><title><![CDATA[Reply to Int zu char Array on Mon, 14 Jul 2014 10:08:20 GMT]]></title><description><![CDATA[<p>Th69 schrieb:</p>
<blockquote>
<p>Übersetzt also in etwa:<br />
In einem Union darf nur auf das zuletzt beschriebene Member lesend zugegriffen werden.</p>
</blockquote>
<p>Das steht dort nicht (oder jedenfalls kann diese Überstzung leicht missverstanden werden). Dort steht nur, dass wenn auf diesen Speicherbereich zugegriffen wird, der gelesene Zustand derjenige ist, der zum zuletzt beschriebenen (=aktiven) Member gehört. Ob dieser Zugriff legal ist oder nicht, wird in diesem Absatz überhaupt nicht diskutiert - dafür empfiehlt ein Blick in 3.10/10. Der Absatz ist deswegen nicht überflüssig: ohne diese Klarstellung wäre nämlich nicht klar, auf welchen gespeicherten Typ sich 3.10/10 beziehen soll.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2408472</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2408472</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Mon, 14 Jul 2014 10:08:20 GMT</pubDate></item><item><title><![CDATA[Reply to Int zu char Array on Mon, 14 Jul 2014 10:14:52 GMT]]></title><description><![CDATA[<blockquote>
<p>In einem Union darf nur auf das zuletzt beschriebene Member lesend zugegriffen werden.</p>
</blockquote>
<p>Falsch. Wo steht etwas von lesen?</p>
<p>Der entscheidende Teil des Standards der es nämlich zu erlauben scheint ist strict aliasing.</p>
<p>§3.10/10 schrieb:</p>
<blockquote>
<p>If a program attempts to access <strong>the stored value of an object</strong> through a glvalue of other than one of the following types the behavior is undefined:<br />
— a char or unsigned char type.</p>
</blockquote>
<p>Ich frage mich dennoch ob die Zeigerarithmetik definiert ist, da doch kein Arrayobjekt existiert...</p>
<blockquote>
<p>Ich würde daraufhin einwenden, dass es in jeder bekannten Implementierung wie gewünscht funktioniert</p>
</blockquote>
<p>GCC kann hier durchaus gruselige Optimierungen durchführen.</p>
<p>Edit: Zu spät.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2408474</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2408474</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Mon, 14 Jul 2014 10:14:52 GMT</pubDate></item><item><title><![CDATA[Reply to Int zu char Array on Mon, 14 Jul 2014 10:18:12 GMT]]></title><description><![CDATA[<p>btw,</p>
<p>SeppJ schrieb:</p>
<blockquote>
<p>Oder einfach casten und direkt auf dem Original arbeiten?</p>
<pre><code>int foo = 7;
	reinterpret_cast&lt;char*&gt;(&amp;foo)[0]=9;
	cout &lt;&lt; foo;
</code></pre>
</blockquote>
<p>keiner hier mag Referenzcasts?</p>
<pre><code class="language-cpp">int foo = 42;
    auto&amp; foo_as_chars = reinterpret_cast&lt;char(&amp;)[]&gt;(foo);
</code></pre>
<p>finde ich viel sprechender in Hinblick auf das, was im Anschluss damit gemacht wird.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2408476</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2408476</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Mon, 14 Jul 2014 10:18:12 GMT</pubDate></item><item><title><![CDATA[Reply to Int zu char Array on Mon, 14 Jul 2014 10:45:59 GMT]]></title><description><![CDATA[<p>camper schrieb:</p>
<blockquote>
<p>btw,</p>
<p>SeppJ schrieb:</p>
<blockquote>
<p>Oder einfach casten und direkt auf dem Original arbeiten?</p>
<pre><code>int foo = 7;
	reinterpret_cast&lt;char*&gt;(&amp;foo)[0]=9;
	cout &lt;&lt; foo;
</code></pre>
</blockquote>
<p>keiner hier mag Referenzcasts?</p>
<pre><code class="language-cpp">int foo = 42;
    auto&amp; foo_as_chars = reinterpret_cast&lt;char(&amp;)[]&gt;(foo);
</code></pre>
<p>finde ich viel sprechender in Hinblick auf das, was im Anschluss damit gemacht wird.</p>
</blockquote>
<p>Seit wann gibts es denn Referenzen auf Arrays of unknown Bound? Kann man die ueberhaupt irgendwie gueltig initialisieren, mal abgesehen von Casts?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2408479</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2408479</guid><dc:creator><![CDATA[Kellerautomat]]></dc:creator><pubDate>Mon, 14 Jul 2014 10:45:59 GMT</pubDate></item><item><title><![CDATA[Reply to Int zu char Array on Mon, 14 Jul 2014 10:58:02 GMT]]></title><description><![CDATA[<p>Kellerautomat schrieb:</p>
<blockquote>
<p>Seit wann gibts es denn Referenzen auf Arrays of unknown Bound? Kann man die ueberhaupt irgendwie gueltig initialisieren, mal abgesehen von Casts?</p>
</blockquote>
<p>Schon immer. Genauso wie du z.B. Referenzen auf noch nicht definierte Klassen haben kannst.</p>
<pre><code class="language-cpp">extern int array[];
int (&amp;ref)[] = array;
int array[4]; // decltype(ref) ist immer noch int(&amp;)[] - der referenzierte Typ wird also nicht nachträglich vollständig
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2408484</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2408484</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Mon, 14 Jul 2014 10:58:02 GMT</pubDate></item><item><title><![CDATA[Reply to Int zu char Array on Mon, 14 Jul 2014 11:01:18 GMT]]></title><description><![CDATA[<p>Ich habe auch eine solche extern-Deklaration ohne Bounds noch nie gesehen. Hat das Ganze irgendeinen praktischen Nutzen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2408486</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2408486</guid><dc:creator><![CDATA[Kellerautomat]]></dc:creator><pubDate>Mon, 14 Jul 2014 11:01:18 GMT</pubDate></item><item><title><![CDATA[Reply to Int zu char Array on Mon, 14 Jul 2014 11:08:06 GMT]]></title><description><![CDATA[<p>Kellerautomat schrieb:</p>
<blockquote>
<p>Ich habe auch eine solche extern-Deklaration ohne Bounds noch nie gesehen. Hat das Ganze irgendeinen praktischen Nutzen?</p>
</blockquote>
<p>Du kannst stehts ein array-to-pointer decay durchfüren und den Zeiger auf das erste Element erhalten. Damit kannst du auch direkt auf die Arrayelemente per Subscript-Operator zugreifen:</p>
<pre><code>extern int arr[];
	arr[5] = 3;
</code></pre>
<p>Gibt dir zwar ggf. einen Linker-, nicht aber einen Compilerfehler. Du kannst also (teilweise eingeschränkt) damit arbeiten.</p>
<p>Das Ganze könnte vielleicht nützlich werden wenn du von ÜE A auf ein Array in ÜE B zugreifen willst, aber unabhängig von der genauen Größe bleiben willst. Einen konkreten Anwendungsfall kenne ich nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2408489</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2408489</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Mon, 14 Jul 2014 11:08:06 GMT</pubDate></item><item><title><![CDATA[Reply to Int zu char Array on Mon, 14 Jul 2014 11:24:23 GMT]]></title><description><![CDATA[<p>Kellerautomat schrieb:</p>
<blockquote>
<p>Ich habe auch eine solche extern-Deklaration ohne Bounds noch nie gesehen.</p>
</blockquote>
<p>Ich auch nicht.</p>
<p>Kellerautomat schrieb:</p>
<blockquote>
<p>Hat das Ganze irgendeinen praktischen Nutzen?</p>
</blockquote>
<p>Vermutlich nicht. Die wenigen denkbaren Anwendungsfälle, die mir einfallen, kann man genauso gut auch anders lösen. Abgesehen von unique_ptr&lt;foo[]&gt; kommen solche Arrays wahrscheinlich nur sehr selten vor. Und selbst diesen Anwendungsfall hätte man recht problemlos anders lösen können, wenn es das Sprachfeature nicht gäbe.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2408494</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2408494</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Mon, 14 Jul 2014 11:24:23 GMT</pubDate></item><item><title><![CDATA[Reply to Int zu char Array on Mon, 14 Jul 2014 11:35:47 GMT]]></title><description><![CDATA[<p>Hallo Camper,</p>
<p>das sog. &quot;type punning&quot; mittels Unions in C++ (11) wird aber von anderen aufgrund dieses Satzes als nicht konform angesehen (auch wenn im Standard nicht explizit von UB die Rede ist - aber es ist ja alles UB was eben nicht im Standard steht ;-):<br />
<a href="http://stackoverflow.com/questions/11373203/accessing-inactive-union-member-undefined" rel="nofollow">http://stackoverflow.com/questions/11373203/accessing-inactive-union-member-undefined</a><br />
<a href="http://stackoverflow.com/questions/2310483/purpose-of-unions-in-c-and-c" rel="nofollow">http://stackoverflow.com/questions/2310483/purpose-of-unions-in-c-and-c</a><br />
<a href="http://stackoverflow.com/questions/6136010/is-using-an-union-in-place-of-a-cast-well-defined" rel="nofollow">http://stackoverflow.com/questions/6136010/is-using-an-union-in-place-of-a-cast-well-defined</a></p>
<p>Und auch unter <a href="http://www.c-plusplus.net/forum/301769" rel="nofollow">union vs reinterpret_cast</a> wird es als UB beschrieben.</p>
<p>Oder doch einfach nur ein Mythos?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2408499</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2408499</guid><dc:creator><![CDATA[Th69]]></dc:creator><pubDate>Mon, 14 Jul 2014 11:35:47 GMT</pubDate></item><item><title><![CDATA[Reply to Int zu char Array on Mon, 14 Jul 2014 12:39:12 GMT]]></title><description><![CDATA[<p>Wenn ich mich da richtig erinnere sagt Bjarne Stroustrup in <em>The C++ Programming Language</em> sinngemäß, dass das Verwenden von Unions zur Typumwandlung obwohl weit verbreitet UB ist und außerdem überflüssig in eine Sprache, die echte Typumwandlungen unterstützt. Er meint, dass sich das eingebürgert habe, da es in manchen Sprachen keine andere Möglichkeit gab.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2408509</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2408509</guid><dc:creator><![CDATA[TNA]]></dc:creator><pubDate>Mon, 14 Jul 2014 12:39:12 GMT</pubDate></item><item><title><![CDATA[Reply to Int zu char Array on Mon, 14 Jul 2014 13:18:12 GMT]]></title><description><![CDATA[<p>Th69 schrieb:</p>
<blockquote>
<p>Hallo Camper,</p>
<p>das sog. &quot;type punning&quot; mittels Unions in C++ (11) wird aber von anderen aufgrund dieses Satzes als nicht konform angesehen (auch wenn im Standard nicht explizit von UB die Rede ist - aber es ist ja alles UB was eben nicht im Standard steht ;-):<br />
<a href="http://stackoverflow.com/questions/11373203/accessing-inactive-union-member-undefined" rel="nofollow">http://stackoverflow.com/questions/11373203/accessing-inactive-union-member-undefined</a><br />
<a href="http://stackoverflow.com/questions/2310483/purpose-of-unions-in-c-and-c" rel="nofollow">http://stackoverflow.com/questions/2310483/purpose-of-unions-in-c-and-c</a><br />
<a href="http://stackoverflow.com/questions/6136010/is-using-an-union-in-place-of-a-cast-well-defined" rel="nofollow">http://stackoverflow.com/questions/6136010/is-using-an-union-in-place-of-a-cast-well-defined</a></p>
<p>Und auch unter <a href="http://www.c-plusplus.net/forum/301769" rel="nofollow">union vs reinterpret_cast</a> wird es als UB beschrieben.</p>
<p>Oder doch einfach nur ein Mythos?</p>
</blockquote>
<p>Ich habe mich nur auf das konkrete Zitat bezogen, dass für sich genommen nicht ausreicht, um UB zu begründen. Zu der allgemeinen Problematik des type-punnings (mit oder ohne union) will ich damit nicht Stellung genommen haben. Der Fall char/unsigned char ist allerdings speziell und immer erlaubt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2408518</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2408518</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Mon, 14 Jul 2014 13:18:12 GMT</pubDate></item><item><title><![CDATA[Reply to Int zu char Array on Mon, 14 Jul 2014 16:47:39 GMT]]></title><description><![CDATA[<p>Arcoth schrieb:</p>
<blockquote>
<blockquote>
<p>Ich würde daraufhin einwenden, dass es in jeder bekannten Implementierung wie gewünscht funktioniert</p>
</blockquote>
<p>GCC kann hier durchaus gruselige Optimierungen durchführen.</p>
</blockquote>
<p>Mein Punkt war: Eben nicht. Soweit ich weiß garantiert der GCC, dass das wie gewünscht funktioniert. Aber ich mag gerade nicht das GCC-Handbuch durchpflügen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2408572</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2408572</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Mon, 14 Jul 2014 16:47:39 GMT</pubDate></item></channel></rss>