<?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[const ref. auf anderen typ]]></title><description><![CDATA[<p>Hi,<br />
kurze Frage dazu:</p>
<pre><code>bool b = true;

	cout &lt;&lt; sizeof(b) &lt;&lt; endl;

	const int&amp; i = b;

	cout &lt;&lt; sizeof(i) &lt;&lt; endl;

	for(int i = 1; i &lt; 4; ++i) // Speicher scheint zugreifbar und Null
		cout &lt;&lt; (int)((char*)&amp;i)[i] &lt;&lt; endl;
</code></pre>
<p>Ausgabe:<br />
1<br />
4<br />
0<br />
0<br />
0</p>
<p>Wird also bei einer (dieser) const ref. eine Stackvariable angelegt? Denn vom bool können die 4 Bytes ja nicht kommen, und wenn sizeof nun 4 ist, kann ich ja im Speicher auch auf 4 Bytes zugreifen, ohne access viol. zu riskieren, oder?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/325577/const-ref-auf-anderen-typ</link><generator>RSS for Node</generator><lastBuildDate>Sun, 12 Jul 2026 04:09:38 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/325577.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 08 May 2014 16:49:28 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to const ref. auf anderen typ on Thu, 08 May 2014 16:49:28 GMT]]></title><description><![CDATA[<p>Hi,<br />
kurze Frage dazu:</p>
<pre><code>bool b = true;

	cout &lt;&lt; sizeof(b) &lt;&lt; endl;

	const int&amp; i = b;

	cout &lt;&lt; sizeof(i) &lt;&lt; endl;

	for(int i = 1; i &lt; 4; ++i) // Speicher scheint zugreifbar und Null
		cout &lt;&lt; (int)((char*)&amp;i)[i] &lt;&lt; endl;
</code></pre>
<p>Ausgabe:<br />
1<br />
4<br />
0<br />
0<br />
0</p>
<p>Wird also bei einer (dieser) const ref. eine Stackvariable angelegt? Denn vom bool können die 4 Bytes ja nicht kommen, und wenn sizeof nun 4 ist, kann ich ja im Speicher auch auf 4 Bytes zugreifen, ohne access viol. zu riskieren, oder?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2398152</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2398152</guid><dc:creator><![CDATA[loboo]]></dc:creator><pubDate>Thu, 08 May 2014 16:49:28 GMT</pubDate></item><item><title><![CDATA[Reply to const ref. auf anderen typ on Thu, 08 May 2014 16:58:02 GMT]]></title><description><![CDATA[<p><code>i</code> ist eine Referenz auf ein neues, namenloses <code>int</code> -Objekt. Dessen Wert wurde aus <code>b</code> konvertiert und müsste <code>1</code> sein.<br />
Deine Schleife gibt die drei letzten Bytes des namenlosen Objektes aus. Du siehst die eins nicht, weil die im ersten Byte steht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2398154</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2398154</guid><dc:creator><![CDATA[TyRoXx]]></dc:creator><pubDate>Thu, 08 May 2014 16:58:02 GMT</pubDate></item><item><title><![CDATA[Reply to const ref. auf anderen typ on Thu, 08 May 2014 17:46:11 GMT]]></title><description><![CDATA[<p>TyRoXx schrieb:</p>
<blockquote>
<p>Du siehst die eins nicht, weil die im ersten Byte steht.</p>
</blockquote>
<p>Jo danke, weiß schon. Ging mir nur darum, ob <em>i</em> eine Stackvariable repräsentiert, oder eben nur reinterpretiert wird (und somit der Speicher von <em>i</em> weiterhin nur 1 Byte groß ist).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2398161</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2398161</guid><dc:creator><![CDATA[loboo]]></dc:creator><pubDate>Thu, 08 May 2014 17:46:11 GMT</pubDate></item><item><title><![CDATA[Reply to const ref. auf anderen typ on Thu, 08 May 2014 17:47:54 GMT]]></title><description><![CDATA[<p>TyRoXx schrieb:</p>
<blockquote>
<p>Deine Schleife gibt die drei letzten Bytes des namenlosen Objektes aus.</p>
</blockquote>
<p>Ich hätte ja gesagt, daß seine Schleife die letzten drei Bytes des schleifenlokalen <code>i</code> durchgeht...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2398163</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2398163</guid><dc:creator><![CDATA[Caligulaminus]]></dc:creator><pubDate>Thu, 08 May 2014 17:47:54 GMT</pubDate></item><item><title><![CDATA[Reply to const ref. auf anderen typ on Thu, 08 May 2014 17:49:24 GMT]]></title><description><![CDATA[<p>Caligulaminus schrieb:</p>
<blockquote>
<p>TyRoXx schrieb:</p>
<blockquote>
<p>Deine Schleife gibt die drei letzten Bytes des namenlosen Objektes aus.</p>
</blockquote>
<p>Ich hätte ja gesagt, daß seine Schleife die letzten drei Bytes des schleifenlokalen <code>i</code> durchgeht...</p>
</blockquote>
<p>Ja, das auch.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2398164</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2398164</guid><dc:creator><![CDATA[TyRoXx]]></dc:creator><pubDate>Thu, 08 May 2014 17:49:24 GMT</pubDate></item><item><title><![CDATA[Reply to const ref. auf anderen typ on Thu, 08 May 2014 17:55:11 GMT]]></title><description><![CDATA[<p>Ups, Ergebnis aber dasselbe <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /><br />
Flüchtigkeitsfehler <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2398169</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2398169</guid><dc:creator><![CDATA[loboo]]></dc:creator><pubDate>Thu, 08 May 2014 17:55:11 GMT</pubDate></item><item><title><![CDATA[Reply to const ref. auf anderen typ on Fri, 09 May 2014 09:12:57 GMT]]></title><description><![CDATA[<p>loboo schrieb:</p>
<blockquote>
<p>Ups, Ergebnis aber dasselbe <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
</blockquote>
<p>Wie &quot;Ergebnis dasselbe&quot;?<br />
Wenn ich beide Fehler korrigiere, bekomme ich:</p>
<pre><code>1
4
1
0
0
0
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2398253</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2398253</guid><dc:creator><![CDATA[Furble Wurble]]></dc:creator><pubDate>Fri, 09 May 2014 09:12:57 GMT</pubDate></item><item><title><![CDATA[Reply to const ref. auf anderen typ on Fri, 09 May 2014 10:11:28 GMT]]></title><description><![CDATA[<p>Achso:<br />
Und ja, da wird ein temporäres Objekt vom Typ int angelegt und mit b initialisiert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2398257</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2398257</guid><dc:creator><![CDATA[Furble Wurble]]></dc:creator><pubDate>Fri, 09 May 2014 10:11:28 GMT</pubDate></item><item><title><![CDATA[Reply to const ref. auf anderen typ on Fri, 09 May 2014 14:46:56 GMT]]></title><description><![CDATA[<p>Furble Wurble schrieb:</p>
<blockquote>
<p>Achso:<br />
Und ja, da wird ein temporäres Objekt vom Typ int angelegt und mit b initialisiert.</p>
</blockquote>
<p>Also eine Stackvariable, auf deren Speicher (hier nun 4 Bytes anstatt 1) man zugreifen kann. Ok.</p>
<p>Furble Wurble schrieb:</p>
<blockquote>
<p>Wie &quot;Ergebnis dasselbe&quot;?<br />
Wenn ich beide Fehler korrigiere, ...</p>
</blockquote>
<p>Ich habe absichtlich bei Index 1 begonnen, auf Byte 1 ist natürlich zugreifbar (bool), und auf Bytes 2-4 der int-Referenz dann scheinbar auch.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2398303</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2398303</guid><dc:creator><![CDATA[loboo]]></dc:creator><pubDate>Fri, 09 May 2014 14:46:56 GMT</pubDate></item></channel></rss>