<?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[new[]]]></title><description><![CDATA[<p>huhu</p>
<p>ist folgender code laut standard well-formed?</p>
<pre><code>bool *_a = new bool[0];
delete[] _a;
</code></pre>
<p>gruss</p>
<p>ps: belehrt mich nun bitte nicht, dass ich einfach std::vector nutzen soll...</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/320174/new</link><generator>RSS for Node</generator><lastBuildDate>Fri, 24 Jul 2026 09:43:51 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/320174.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 19 Sep 2013 10:19:44 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to new[] on Thu, 19 Sep 2013 10:19:44 GMT]]></title><description><![CDATA[<p>huhu</p>
<p>ist folgender code laut standard well-formed?</p>
<pre><code>bool *_a = new bool[0];
delete[] _a;
</code></pre>
<p>gruss</p>
<p>ps: belehrt mich nun bitte nicht, dass ich einfach std::vector nutzen soll...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2353652</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2353652</guid><dc:creator><![CDATA[doktor banane]]></dc:creator><pubDate>Thu, 19 Sep 2013 10:19:44 GMT</pubDate></item><item><title><![CDATA[Reply to new[] on Thu, 19 Sep 2013 10:43:01 GMT]]></title><description><![CDATA[<pre><code>new bool[0];
</code></pre>
<p>Ja, das funktioniert und ist definiert:</p>
<p>5.3.4/5 schrieb:</p>
<blockquote>
<p>When the value of the expression in a noptr-new-declarator is zero, the allocation function is called to allocate an array with no elements.</p>
</blockquote>
<p>Entsprechend funktioniert dann auch das Zerstoeren.</p>
<p><strong>Edit</strong>: Nein, das sollte nicht kompilieren, siehe unten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2353655</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2353655</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Thu, 19 Sep 2013 10:43:01 GMT</pubDate></item><item><title><![CDATA[Reply to new[] on Thu, 19 Sep 2013 10:29:07 GMT]]></title><description><![CDATA[<p>Was willst du damit bezwecken? Ein pointer, der auf 0 Elemente zeigt, kann genausogut auf nichts zeigen (nullptr).</p>
<p>Außerdem ist new und delete nicht exceptionsafe, aber ich denke mal, dass du hier einen zeitkritischen Codeabschnitt hast oder nur aus Interesse fragst, sonst würdest du ja vector nutzen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2353656</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2353656</guid><dc:creator><![CDATA[Marthog]]></dc:creator><pubDate>Thu, 19 Sep 2013 10:29:07 GMT</pubDate></item><item><title><![CDATA[Reply to new[] on Thu, 19 Sep 2013 10:34:21 GMT]]></title><description><![CDATA[<p>Sone schrieb:</p>
<blockquote>
<pre><code>new bool[0];
</code></pre>
<p>Ja, das funktioniert und ist definiert:</p>
<p>5.3.4/5 schrieb:</p>
<blockquote>
<p>When the value of the expression in a noptr-new-declarator is zero, the allocation function is called to allocate an array with no elements.</p>
</blockquote>
<p>Entsprechend funktioniert dann auch das Zerstoeren.</p>
</blockquote>
<p>okay, perfekt, vielen dank.</p>
<p>Marthog schrieb:</p>
<blockquote>
<p>Was willst du damit bezwecken? Ein pointer, der auf 0 Elemente zeigt, kann genausogut auf nichts zeigen (nullptr).</p>
</blockquote>
<p>ja, ich selbst schreibe ja in meinem code natürlich nicht, dass ich 0 elemente mit new[] erzeugen will, eher wird die anzahl der elemente durch eine berechnung bestimmt, welche unter umständen auch 0 ergeben kann.</p>
<p>Marthog schrieb:</p>
<blockquote>
<p>Außerdem ist new und delete nicht exceptionsafe, aber ich denke mal, dass du hier einen zeitkritischen Codeabschnitt hast oder nur aus Interesse fragst, sonst würdest du ja vector nutzen.</p>
</blockquote>
<p>ja, ich bastle hobbymässig an einem zellularen automaten rum.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2353657</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2353657</guid><dc:creator><![CDATA[doktor banane]]></dc:creator><pubDate>Thu, 19 Sep 2013 10:34:21 GMT</pubDate></item><item><title><![CDATA[Reply to new[] on Thu, 19 Sep 2013 10:36:30 GMT]]></title><description><![CDATA[<p>Gerade in zeitkritischem Code will man kein new und delete haben... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>Abgesehen davon, gibt es keinen Grund, nicht zumindest Smart Pointer zu verwenden... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2353659</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2353659</guid><dc:creator><![CDATA[dot]]></dc:creator><pubDate>Thu, 19 Sep 2013 10:36:30 GMT</pubDate></item><item><title><![CDATA[Reply to new[] on Thu, 19 Sep 2013 11:48:06 GMT]]></title><description><![CDATA[<p>Oh, Stop! Nein, das sollte (ohne es jetzt zu pruefen) gar nicht kompilieren:</p>
<blockquote>
<p>Every <strong>constant-expression</strong> in a noptr-new-declarator shall be an integral constant expression (5.19) and evaluate to a <strong>strictly positive value</strong>.</p>
</blockquote>
<p>Das heisst, es darf 0 vorkommen, aber nur, wenn die Bounds zur Laufzeit vorgegeben werden. Wenn du da tatsaechlich 0 als Literal reinschreibst, dann darf das nicht kompilieren.</p>
<p><a href="http://ideone.com/RlQ3sK" rel="nofollow">Ideone sagt hingegegen das Gegenteil</a>, daher ist der GCC 4.8.1 in diesem Fall nicht standardkonform.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2353660</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2353660</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Thu, 19 Sep 2013 11:48:06 GMT</pubDate></item><item><title><![CDATA[Reply to new[] on Thu, 19 Sep 2013 10:46:05 GMT]]></title><description><![CDATA[<p>Sone schrieb:</p>
<blockquote>
<p><a href="http://ideone.com/RlQ3sK" rel="nofollow">Ideone sagt hingegegen das Gegenteil</a>, daher ist der GCC 4.8.1 in diesem Fall nicht standardkonform.</p>
</blockquote>
<p>Jo, zero size Arrays sind ein relativ verbreitete Spracherweiterung... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2353668</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2353668</guid><dc:creator><![CDATA[dot]]></dc:creator><pubDate>Thu, 19 Sep 2013 10:46:05 GMT</pubDate></item><item><title><![CDATA[Reply to new[] on Thu, 19 Sep 2013 10:47:47 GMT]]></title><description><![CDATA[<p>Sone schrieb:</p>
<blockquote>
<p>Oh, Stop! Nein, das sollte (ohne es jetzt zu pruefen) <strong>gar nicht kompilieren</strong>:</p>
<blockquote>
<p>Every <strong>constant-expression</strong> in a noptr-new-declarator shall be an integral constant expression (5.19) and evaluate to a <strong>strictly positive value</strong>.</p>
</blockquote>
<p>(<strong>strictly positive</strong> heisst, nicht negativ und nicht null)<br />
Das heisst, es darf 0 vorkommen, aber nur, wenn die Bounds zur Laufzeit vorgegeben werden. Wenn du da tatsaechlich 0 als Literal reinschreibst, dann darf das nicht kompilieren.</p>
<p><a href="http://ideone.com/RlQ3sK" rel="nofollow">Ideone sagt hingegegen das Gegenteil</a>, daher ist der GCC 4.8.1 in diesem Fall nicht standardkonform.</p>
</blockquote>
<p>hm und wie ist es, wenn es etwa so aussieht?</p>
<pre><code>class c
{
    bool *_d;
    c();
public:
    c(unsigned l) : _d(new bool[l]) {}
};
int main()
{
    c instance(0);
}
</code></pre>
<p>hier schreibe ich in die eckigen klammern des new[]-operators selbst kein literal rein, die variable l lässt sich jedoch auf ein literal zurückführen. ist das dann okay?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2353669</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2353669</guid><dc:creator><![CDATA[doktor banane]]></dc:creator><pubDate>Thu, 19 Sep 2013 10:47:47 GMT</pubDate></item><item><title><![CDATA[Reply to new[] on Thu, 19 Sep 2013 10:56:46 GMT]]></title><description><![CDATA[<p>doktor banane schrieb:</p>
<blockquote>
<p>hier schreibe ich in die eckigen klammern des new[]-operators selbst kein literal rein, die variable l lässt sich jedoch auf ein literal zurückführen. ist das dann okay?</p>
</blockquote>
<p>Ja, aber wofür brauchst du das genau?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2353674</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2353674</guid><dc:creator><![CDATA[dot]]></dc:creator><pubDate>Thu, 19 Sep 2013 10:56:46 GMT</pubDate></item><item><title><![CDATA[Reply to new[] on Thu, 19 Sep 2013 11:01:06 GMT]]></title><description><![CDATA[<p>Das ist ok, denn in diesem Fall ist l keine constant expression.</p>
<p>Ganz sicher bin ich nicht, warten wir auf camper.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2353675</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2353675</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Thu, 19 Sep 2013 11:01:06 GMT</pubDate></item><item><title><![CDATA[Reply to new[] on Thu, 19 Sep 2013 11:08:40 GMT]]></title><description><![CDATA[<p>Sone schrieb:</p>
<blockquote>
<p>Ganz sicher bin ich nicht, warten wir auf camper.</p>
</blockquote>
<p>Es stimmt schon so wie du sagst. Arrays dürfen laut Standard nicht Größe 0 haben, an new[] darf dagegen 0 übergeben werden. Zero sized Arrays werden als Spracherweiterung allerdings von vielen Compilern unterstützt...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2353679</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2353679</guid><dc:creator><![CDATA[dot]]></dc:creator><pubDate>Thu, 19 Sep 2013 11:08:40 GMT</pubDate></item><item><title><![CDATA[Reply to new[] on Thu, 19 Sep 2013 11:29:17 GMT]]></title><description><![CDATA[<p>doktor banane schrieb:</p>
<blockquote>
<p>ja, ich selbst schreibe ja in meinem code natürlich nicht, dass ich 0 elemente mit new[] erzeugen will, eher wird die anzahl der elemente durch eine berechnung bestimmt, welche unter umständen auch 0 ergeben kann.</p>
</blockquote>
<p>dot schrieb:</p>
<blockquote>
<p>Gerade in zeitkritischem Code will man kein new und delete haben... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
</blockquote>
<p>Ja. Die Abfrage, ob der Wert gültig ist, ist deutlich effizienter, als ein unnötiger new[] oder delete[] call.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2353683</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2353683</guid><dc:creator><![CDATA[Marthog]]></dc:creator><pubDate>Thu, 19 Sep 2013 11:29:17 GMT</pubDate></item><item><title><![CDATA[Reply to new[] on Thu, 19 Sep 2013 11:17:58 GMT]]></title><description><![CDATA[<p>[/quote]als Spracherweiterung[/quote]Hmm ...<br />
<a href="http://stackoverflow.com/questions/1087042/c-new-int0-will-it-allocate-memory" rel="nofollow">http://stackoverflow.com/questions/1087042/c-new-int0-will-it-allocate-memory</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2353684</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2353684</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Thu, 19 Sep 2013 11:17:58 GMT</pubDate></item><item><title><![CDATA[Reply to new[] on Thu, 19 Sep 2013 11:24:56 GMT]]></title><description><![CDATA[<p>knivil schrieb:</p>
<blockquote>
<blockquote>
<p>als Spracherweiterung</p>
</blockquote>
<p>Hmm ...<br />
<a href="http://stackoverflow.com/questions/1087042/c-new-int0-will-it-allocate-memory" rel="nofollow">http://stackoverflow.com/questions/1087042/c-new-int0-will-it-allocate-memory</a></p>
</blockquote>
<p>Wie gesagt, <code>new T[0]</code> ist durch eine Ausnahmeregelgung laut Standard erlaubt, <code>T blub[0];</code> dagegen nicht, wird aber von einigen Compilern dennoch unterstützt... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2353688</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2353688</guid><dc:creator><![CDATA[dot]]></dc:creator><pubDate>Thu, 19 Sep 2013 11:24:56 GMT</pubDate></item><item><title><![CDATA[Reply to new[] on Thu, 19 Sep 2013 12:16:30 GMT]]></title><description><![CDATA[<blockquote>
<p>Wie gesagt, new T[0] ist durch eine Ausnahmeregelgung laut Standard erlaubt</p>
</blockquote>
<p>Nein, ist es ja gerade nicht!</p>
<blockquote>
<p>Arrays dürfen laut Standard nicht Größe 0 haben, an new[] darf dagegen 0 übergeben werden.</p>
</blockquote>
<p>Hast du überhaupt meine Zitate gelesen/verstanden?</p>
<p>Es ging nie um normale Arrays, meine Zitate bezogen sich alle auf <code>new</code> . Und mein letztes hat AFAICS klar gezeigt, dass es nicht erlaubt ist... bzw. sein sollte.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2353692</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2353692</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Thu, 19 Sep 2013 12:16:30 GMT</pubDate></item><item><title><![CDATA[Reply to new[] on Thu, 19 Sep 2013 11:35:43 GMT]]></title><description><![CDATA[<p>Also laut Sutter ist new T[0] erlaubt:<br />
<a href="http://herbsutter.com/2009/09/02/when-is-a-zero-length-array-okay/" rel="nofollow">http://herbsutter.com/2009/09/02/when-is-a-zero-length-array-okay/</a></p>
<p>ich habe nur keinen Standard bei der Hand aber prinzipiell vertraue ich Sutter bei sowas blind.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2353696</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2353696</guid><dc:creator><![CDATA[Shade Of Mine]]></dc:creator><pubDate>Thu, 19 Sep 2013 11:35:43 GMT</pubDate></item><item><title><![CDATA[Reply to new[] on Thu, 19 Sep 2013 11:44:57 GMT]]></title><description><![CDATA[<p>Ja, Sutter hat Recht. Ich habe mich vertan, bei den Zitaten...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2353700</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2353700</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Thu, 19 Sep 2013 11:44:57 GMT</pubDate></item><item><title><![CDATA[Reply to new[] on Thu, 19 Sep 2013 11:41:59 GMT]]></title><description><![CDATA[<p>Sone schrieb:</p>
<blockquote>
<blockquote>
<p>Wie gesagt, new T[0] ist durch eine Ausnahmeregelgung laut Standard erlaubt</p>
</blockquote>
<p>Nein, ist es ja gerade nicht!</p>
<blockquote>
<p>Arrays dürfen laut Standard nicht Größe 0 haben, an new[] darf dagegen 0 übergeben werden.</p>
</blockquote>
<p>Hast du überhaupt meine Zitate gelesen/verstanden?</p>
</blockquote>
<p>Nach meiner Interpretation kommt der Part mit der constant expression nur bei mehrdimensionalen Arrays zu tragen, was auch Sinn macht... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2353702</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2353702</guid><dc:creator><![CDATA[dot]]></dc:creator><pubDate>Thu, 19 Sep 2013 11:41:59 GMT</pubDate></item><item><title><![CDATA[Reply to new[] on Thu, 19 Sep 2013 12:14:26 GMT]]></title><description><![CDATA[<p>dot schrieb:</p>
<blockquote>
<p>Nach meiner Interpretation, kommt der Part mit der constant expression nur bei mehrdimensionalen Arrays zu tragen, was auch Sinn macht... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
</blockquote>
<p>Jetzt hast du mich aber am Haken. Wie interpretierst du das denn genau? <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>
<p>Oh.... verdammt... du hast Recht. Das bezieht sich auf Multidimensionale Arrays... ich wusste, da stimmt was nicht... ja, ich habe die Zitate nicht verstanden, verdammt. Die sind auch immer sowas von nicht selbsterklärend.</p>
<p>Ja, da hast du Recht. Bei Multidimensionalen Heap-Arrays müssten die zusätzlichen Dimensionen alle konstant und strikt positiv sein. Sonst kann auch 0 benutzt werden. Das heißt der Code im OP ist richtig.</p>
<blockquote>
<p>hier schreibe ich in die eckigen klammern des new[]-operators selbst kein literal rein, die variable l lässt sich jedoch auf ein literal zurückführen. ist das dann okay?</p>
</blockquote>
<p>Es wäre auch Ok, wenn du das Literal direkt reinschreibst, wie du siehst, habe ich mich vertan.... <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>
]]></description><link>https://www.c-plusplus.net/forum/post/2353704</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2353704</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Thu, 19 Sep 2013 12:14:26 GMT</pubDate></item><item><title><![CDATA[Reply to new[] on Thu, 19 Sep 2013 11:53:24 GMT]]></title><description><![CDATA[<p>Muss aber zugeben, ich hab mich davon auch erstmal verwirren lassen... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2353706</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2353706</guid><dc:creator><![CDATA[dot]]></dc:creator><pubDate>Thu, 19 Sep 2013 11:53:24 GMT</pubDate></item><item><title><![CDATA[Reply to new[] on Thu, 19 Sep 2013 11:53:27 GMT]]></title><description><![CDATA[<p>Sone schrieb:</p>
<blockquote>
<p>Ganz sicher bin ich nicht, warten wir auf camper.</p>
</blockquote>
<p>Sone schrieb:</p>
<blockquote>
<p>Ja, Sutter hat Recht. Ich habe mich vertan, bei den Zitaten...</p>
</blockquote>
<p>Sone schrieb:</p>
<blockquote>
<p>Oh.... verdammt... du hast Recht. Das bezieht sich auf Multidimensionale Arrays... ich wusste, da stimmt was nicht... ja, ich habe die Zitate nicht verstanden, verdammt. Die sind auch immer sowas von nicht selbsterklärend.</p>
</blockquote>
<p>Wieder ein typischer Sone-Multifail.<br />
Im Gegensatz zur Situation vor einem Jahr hat sich eigentlich nur geändert, dass Du ständig den Standard zitierst aber kaum verstehst was drin steht.<br />
Endlich mal Fresse halten?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2353707</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2353707</guid><dc:creator><![CDATA[Multi-Pass]]></dc:creator><pubDate>Thu, 19 Sep 2013 11:53:27 GMT</pubDate></item><item><title><![CDATA[Reply to new[] on Thu, 19 Sep 2013 12:06:54 GMT]]></title><description><![CDATA[<blockquote>
<p>dass Du ständig den Standard zitierst aber kaum verstehst was drin steht.</p>
</blockquote>
<p>Nein, ich verstehe prinzipiell gut was drin steht. Das war ein verwirrender Fall.</p>
<p>Zeig mir nochmal den letzten, wo ich den Standard zitiere und &quot;kaum verstehe was drin steht&quot;.</p>
<blockquote>
<p>Endlich mal Fresse halten?</p>
</blockquote>
<p>Wieso sollte ich?</p>
<p>Btw, was genau ist ein Multifail? Ich hatte nur ein Zitat falsch gedeutet, das ist alles. Und dabei das richtige noch im ersten Post gebracht. Das ist nichts schlimmes. Aber ich wusste genau, das gleich der nächste Spinner ankommt und das für seine Anti-Sone Kampagne ausnutzt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2353708</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2353708</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Thu, 19 Sep 2013 12:06:54 GMT</pubDate></item><item><title><![CDATA[Reply to new[] on Thu, 19 Sep 2013 12:11:18 GMT]]></title><description><![CDATA[<p>okay, ich habe die diskussion soweit passiv beobachtet und bedanke mich nun für die aufklärung.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2353710</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2353710</guid><dc:creator><![CDATA[doktor banane]]></dc:creator><pubDate>Thu, 19 Sep 2013 12:11:18 GMT</pubDate></item><item><title><![CDATA[Reply to new[] on Thu, 19 Sep 2013 12:23:12 GMT]]></title><description><![CDATA[<p>doktor banane schrieb:</p>
<blockquote>
<p>okay, ich habe die diskussion soweit passiv beobachtet und bedanke mich nun für die aufklärung.</p>
</blockquote>
<p>Da du nun aber schon auf der ersten Seite den Anwendungsfall genannt und den Code gezeigt hast, fühl' ich mich verpflichtet, dich davon zu unterrichten, dass das keine gute Idee ist, auch wenn es nun doch erlaubt ist:</p>
<pre><code>class c 
{ 
    bool *_d; 
    c(); 
public: 
    c(unsigned l) : _d(new bool[l]) {} 
};
</code></pre>
<p>Vektoren darfst du genauso problemlos mit jeder Größe initialisieren, und ich bezweifle, dass der Performance-Verlust so groß ist..<br />
Falls doch, und die Performance sollte dann <strong>wirklich</strong> Druck machen, solltest du auf RAII achten um zumindest die Exception-Safety zu garantieren.</p>
<p>Und außerdem Marthogs Tipp beachten:</p>
<blockquote>
<p>Ja. Die Abfrage, ob der Wert gültig ist, ist deutlich effizienter, als ein unnötiger new[] oder delete[] call.</p>
</blockquote>
<p>Zumindest den Ctor also so umschreiben:</p>
<pre><code>c(unsigned l) : _d(l ? new bool[l] : nullptr /*bzw. einfach NULL/0 */) {}
</code></pre>
<p>Für sowas gibt es bspw. <a href="http://www.boost.org/doc/libs/1_54_0/libs/smart_ptr/scoped_array.htm" rel="nofollow">boost::scoped_array</a>.</p>
<p>Wie gesagt, wahrscheinlich kannst du auch <code>vector</code> benutzen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2353711</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2353711</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Thu, 19 Sep 2013 12:23:12 GMT</pubDate></item><item><title><![CDATA[Reply to new[] on Thu, 19 Sep 2013 12:46:57 GMT]]></title><description><![CDATA[<p>Sone schrieb:</p>
<blockquote>
<p>Oh, Stop! Nein, das sollte (ohne es jetzt zu pruefen) gar nicht kompilieren:</p>
<blockquote>
<p>Every <strong>constant-expression</strong> in a noptr-new-declarator shall be an integral constant expression (5.19) and evaluate to a <strong>strictly positive value</strong>.</p>
</blockquote>
<p>Das heisst, es darf 0 vorkommen, aber nur, wenn die Bounds zur Laufzeit vorgegeben werden. Wenn du da tatsaechlich 0 als Literal reinschreibst, dann darf das nicht kompilieren.</p>
</blockquote>
<p>Das Problem hier ist das fehlerhafte Zitieren.<br />
<em>constant-expression</em> ist kursiv, und das bezieht sich folglich (siehe 1.6) auf die Syntaxkategorie (folglich muss man automatisch noch einen Blick auf die Grammatik werfen, um den Sinn der Aussage zu erfassen) und nicht konstante Ausdrücke im Allgemeinen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2353717</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2353717</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Thu, 19 Sep 2013 12:46:57 GMT</pubDate></item></channel></rss>