<?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[Rohes array und nicht konstante Größe]]></title><description><![CDATA[<p>Hallo,</p>
<p>mal eine Frage. Ich habe Code folgender Art schon öfter mal bei ein paar Kommilitonen gesehen:</p>
<pre><code>#include &lt;iostream&gt;

int main()
{
	int len = 10, cnt = 0;
	int arr[len];

	for (auto &amp;i : arr) {
		i = ++cnt;
	}
	for (auto const &amp;i : arr) {
		std::cout &lt;&lt; i &lt;&lt; '\n';
	}
}
</code></pre>
<p>Bei denen Funktioniert das auch, bei mir (Visual Studio 2013) kompiliert sowas allerdings nicht (len ist kein konstanter Wert).</p>
<p>Daher gehe ich mal davon aus dass es nicht dem Standard entspricht?</p>
<p>Vor allem interessiert mich: Hat man hier ein (potentielles) Memory-Leak? Oder führt der Compiler bei so einem (dynamisch) erzeugtem array auch die entsprechenden Deallokationen automatisch mit ein?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/328780/rohes-array-und-nicht-konstante-größe</link><generator>RSS for Node</generator><lastBuildDate>Tue, 07 Jul 2026 07:47:39 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/328780.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 26 Oct 2014 18:26:10 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Rohes array und nicht konstante Größe on Sun, 26 Oct 2014 18:26:10 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>mal eine Frage. Ich habe Code folgender Art schon öfter mal bei ein paar Kommilitonen gesehen:</p>
<pre><code>#include &lt;iostream&gt;

int main()
{
	int len = 10, cnt = 0;
	int arr[len];

	for (auto &amp;i : arr) {
		i = ++cnt;
	}
	for (auto const &amp;i : arr) {
		std::cout &lt;&lt; i &lt;&lt; '\n';
	}
}
</code></pre>
<p>Bei denen Funktioniert das auch, bei mir (Visual Studio 2013) kompiliert sowas allerdings nicht (len ist kein konstanter Wert).</p>
<p>Daher gehe ich mal davon aus dass es nicht dem Standard entspricht?</p>
<p>Vor allem interessiert mich: Hat man hier ein (potentielles) Memory-Leak? Oder führt der Compiler bei so einem (dynamisch) erzeugtem array auch die entsprechenden Deallokationen automatisch mit ein?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2424169</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2424169</guid><dc:creator><![CDATA[happystudent]]></dc:creator><pubDate>Sun, 26 Oct 2014 18:26:10 GMT</pubDate></item><item><title><![CDATA[Reply to Rohes array und nicht konstante Größe on Sun, 26 Oct 2014 18:34:19 GMT]]></title><description><![CDATA[<p>Das nennt sich Variable Length Array (VLA).<br />
Die werden auf dem Stack alloziert und automatisch beim Verlassen des Stack-Frames, d.h. der Funktion, freigegeben. Der Speicher ist wesentlich schneller &quot;da&quot; als new oder malloc.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2424172</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2424172</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Sun, 26 Oct 2014 18:34:19 GMT</pubDate></item><item><title><![CDATA[Reply to Rohes array und nicht konstante Größe on Sun, 26 Oct 2014 18:42:17 GMT]]></title><description><![CDATA[<p>Ach so, Ok. Ich dachte der Compiler fügt da einfach ein &quot;new&quot; ein sozusagen.</p>
<p>Alles klar, vielen Dank <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2424175</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2424175</guid><dc:creator><![CDATA[happystudent]]></dc:creator><pubDate>Sun, 26 Oct 2014 18:42:17 GMT</pubDate></item><item><title><![CDATA[Reply to Rohes array und nicht konstante Größe on Sun, 26 Oct 2014 20:55:14 GMT]]></title><description><![CDATA[<p>Gibt es VLAs nicht nur in C?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2424204</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2424204</guid><dc:creator><![CDATA[patrick246]]></dc:creator><pubDate>Sun, 26 Oct 2014 20:55:14 GMT</pubDate></item><item><title><![CDATA[Reply to Rohes array und nicht konstante Größe on Sun, 26 Oct 2014 20:59:01 GMT]]></title><description><![CDATA[<p>Der Grund warum das bei denen funktioniert ist vermutlich dass sie GCC verwenden. Oder sonst einen Compiler der VLAs in C++ Code als non-Standard Extension unterstützt.<br />
MSVC tut es nicht, daher spuckt er auch nen entsprechenden Fehler aus.</p>
<p>patrick246 schrieb:</p>
<blockquote>
<p>Gibt es VLAs nicht nur in C?</p>
</blockquote>
<p>Offiziell ja, aber es gibt Compiler die es in C++ als Extension anbieten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2424205</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2424205</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Sun, 26 Oct 2014 20:59:01 GMT</pubDate></item></channel></rss>