<?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[struct initialisieren?]]></title><description><![CDATA[<p>Ich hab ein struct (und ein deja vù :D), welches ne Vielzahl an Typen hat, von Pointern bis zu ints.</p>
<p>Wenn ich diesen deklariere, à la</p>
<pre><code class="language-cpp">T * t = new T();
</code></pre>
<p>haben die Typen alle alles mögliche an Werten, kann man diese typen default initialisieren, so wie es calloc macht? Nur auf C++ niveau?</p>
<p>An den struct selber komme ich nicht dran,kann ihn also nicht ändern und ich nutze auto_ptr für T, ergo kann ich nichts calloc'en wenn auto_ptr danach delete aufruft.</p>
<p>Gibt es keinen Weg, dass new intern calloc und nicht malloc nutzt?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/225411/struct-initialisieren</link><generator>RSS for Node</generator><lastBuildDate>Thu, 01 Oct 2026 12:12:01 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/225411.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 23 Oct 2008 07:12:46 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to struct initialisieren? on Thu, 23 Oct 2008 07:18:32 GMT]]></title><description><![CDATA[<p>Ich hab ein struct (und ein deja vù :D), welches ne Vielzahl an Typen hat, von Pointern bis zu ints.</p>
<p>Wenn ich diesen deklariere, à la</p>
<pre><code class="language-cpp">T * t = new T();
</code></pre>
<p>haben die Typen alle alles mögliche an Werten, kann man diese typen default initialisieren, so wie es calloc macht? Nur auf C++ niveau?</p>
<p>An den struct selber komme ich nicht dran,kann ihn also nicht ändern und ich nutze auto_ptr für T, ergo kann ich nichts calloc'en wenn auto_ptr danach delete aufruft.</p>
<p>Gibt es keinen Weg, dass new intern calloc und nicht malloc nutzt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1603181</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1603181</guid><dc:creator><![CDATA[Seikilos]]></dc:creator><pubDate>Thu, 23 Oct 2008 07:18:32 GMT</pubDate></item><item><title><![CDATA[Reply to struct initialisieren? on Thu, 23 Oct 2008 07:20:56 GMT]]></title><description><![CDATA[<p>dafür gibts konstruktoren. new hat mit malloc übrigens gar nichts zu tun.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1603187</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1603187</guid><dc:creator><![CDATA[poiuzwerf]]></dc:creator><pubDate>Thu, 23 Oct 2008 07:20:56 GMT</pubDate></item><item><title><![CDATA[Reply to struct initialisieren? on Thu, 23 Oct 2008 07:21:15 GMT]]></title><description><![CDATA[<p>Du könntest doch mit memset null-initialisieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1603188</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1603188</guid><dc:creator><![CDATA[_matze]]></dc:creator><pubDate>Thu, 23 Oct 2008 07:21:15 GMT</pubDate></item><item><title><![CDATA[Reply to struct initialisieren? on Thu, 23 Oct 2008 07:22:07 GMT]]></title><description><![CDATA[<p>poiuzwerf schrieb:</p>
<blockquote>
<p>new hat mit malloc übrigens gar nichts zu tun.</p>
</blockquote>
<p>In vielen Implementierungen wird intern malloc verwendet. Die Diskussion gab's schon öfter...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1603189</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1603189</guid><dc:creator><![CDATA[_matze]]></dc:creator><pubDate>Thu, 23 Oct 2008 07:22:07 GMT</pubDate></item><item><title><![CDATA[Reply to struct initialisieren? on Thu, 23 Oct 2008 07:22:09 GMT]]></title><description><![CDATA[<p>bzw. wenn du die struct nicht ändern kannst, schreib eine initialisierungsfunktion.</p>
<pre><code class="language-cpp">void initT(T&amp; bla)
{
  bla.intvalue = 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1603190</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1603190</guid><dc:creator><![CDATA[üppoiuzwerf]]></dc:creator><pubDate>Thu, 23 Oct 2008 07:22:09 GMT</pubDate></item><item><title><![CDATA[Reply to struct initialisieren? on Thu, 23 Oct 2008 07:24:02 GMT]]></title><description><![CDATA[<p>Laut wiki schon.</p>
<p>Der Haken: Ich hab ein automatisch generiertes c-struct, da hilft mir kein konstruktor, nur ist es schwierig ein c-struct, das mit calloc alloziiert worden ist, in einen smart pointer zu stopfen</p>
<p>Edit: Nicht so schnell: Das per Hand initliaiseren will ich umgehen, ist ne Menge arbeit.</p>
<p>memset werd ich angucken</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1603191</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1603191</guid><dc:creator><![CDATA[Seikilos]]></dc:creator><pubDate>Thu, 23 Oct 2008 07:24:02 GMT</pubDate></item><item><title><![CDATA[Reply to struct initialisieren? on Thu, 23 Oct 2008 07:23:24 GMT]]></title><description><![CDATA[<p>_matze schrieb:</p>
<blockquote>
<p>Du könntest doch mit memset null-initialisieren.</p>
</blockquote>
<p>nein, tu das lieber nicht.</p>
<p>_matze schrieb:</p>
<blockquote>
<p>In vielen Implementierungen wird intern malloc verwendet. Die Diskussion gab's schon öfter...</p>
</blockquote>
<p>new hat mit malloc nichts zu tun. was &quot;viele implementierungen&quot; tun, interessiert nicht die bohne.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1603192</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1603192</guid><dc:creator><![CDATA[poiuzwerf]]></dc:creator><pubDate>Thu, 23 Oct 2008 07:23:24 GMT</pubDate></item><item><title><![CDATA[Reply to struct initialisieren? on Thu, 23 Oct 2008 07:26:00 GMT]]></title><description><![CDATA[<p>Es klappt mit memset, aber wieso soll ich es nicht tun?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1603193</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1603193</guid><dc:creator><![CDATA[Seikilos]]></dc:creator><pubDate>Thu, 23 Oct 2008 07:26:00 GMT</pubDate></item><item><title><![CDATA[Reply to struct initialisieren? on Thu, 23 Oct 2008 07:26:33 GMT]]></title><description><![CDATA[<p>Seikilos schrieb:</p>
<blockquote>
<p>Es klappt mit memset, aber wieso soll ich es nicht tun?</p>
</blockquote>
<pre><code class="language-cpp">struct bumm
{
    std::string patsch;
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1603195</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1603195</guid><dc:creator><![CDATA[poiuzwerf]]></dc:creator><pubDate>Thu, 23 Oct 2008 07:26:33 GMT</pubDate></item><item><title><![CDATA[Reply to struct initialisieren? on Thu, 23 Oct 2008 07:29:15 GMT]]></title><description><![CDATA[<p>in nem c struct?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1603196</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1603196</guid><dc:creator><![CDATA[Seikilos]]></dc:creator><pubDate>Thu, 23 Oct 2008 07:29:15 GMT</pubDate></item><item><title><![CDATA[Reply to struct initialisieren? on Thu, 23 Oct 2008 07:35:02 GMT]]></title><description><![CDATA[<p>Seikilos schrieb:</p>
<blockquote>
<p>in nem c struct?</p>
</blockquote>
<p>wenn du 100% sicher bist, dass da immer nur PODs drin stecken, kannst du es mit memset machen. dann könntest du aber auch gleich calloc benutzen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1603199</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1603199</guid><dc:creator><![CDATA[poiuzwerf]]></dc:creator><pubDate>Thu, 23 Oct 2008 07:35:02 GMT</pubDate></item><item><title><![CDATA[Reply to struct initialisieren? on Thu, 23 Oct 2008 07:40:05 GMT]]></title><description><![CDATA[<p>Ja, aber wie kann ich dann den speicher in nem smart pointer verwalten?</p>
<p>auto_ptr macht doch ein delete, aber da es nicht mit new erzeugt worden ist?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1603202</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1603202</guid><dc:creator><![CDATA[Seikilos]]></dc:creator><pubDate>Thu, 23 Oct 2008 07:40:05 GMT</pubDate></item><item><title><![CDATA[Reply to struct initialisieren? on Thu, 23 Oct 2008 08:07:13 GMT]]></title><description><![CDATA[<p>Seikilos schrieb:</p>
<blockquote>
<p>Ja, aber wie kann ich dann den speicher in nem smart pointer verwalten?</p>
<p>auto_ptr macht doch ein delete, aber da es nicht mit new erzeugt worden ist?</p>
</blockquote>
<p>Wenn Du die Dinger wirklich in einem auto_ptr verwalten willst, kannst Du eine Initialisiererfunktion schreiben:</p>
<pre><code class="language-cpp">struct SomeStrangeStruct
{
    int intVal;
    float floatVal;
    char charArr[4];
    double* doublePtr;
};

SomeStrangeStruct* initializerFunkt()
{
    SomeStrangeStruct* structure = new SomeStrangeStruct();
    structure-&gt;intVal = 0;
    structure-&gt;floatVal = 0.0f;
    std::fill(structure-&gt;charArr, structure-&gt;charArr + sizeof(structure-&gt;charArr), 'a');
    structure-&gt;doublePtr = NULL;
    return structure;
}

//...
std::auto_ptr&lt;SomeStrangeStruct&gt; structAutoPtr(initializerFunkt());
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1603215</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1603215</guid><dc:creator><![CDATA[Tachyon]]></dc:creator><pubDate>Thu, 23 Oct 2008 08:07:13 GMT</pubDate></item><item><title><![CDATA[Reply to struct initialisieren? on Thu, 23 Oct 2008 08:11:45 GMT]]></title><description><![CDATA[<p>Dies tu ich in der Tat auch, nur das die init mehr als 100 Zeilen hätte und ich dies gerne vermeiden würde. memset kommt mir da schon zu gute.</p>
<p>Ich wollte nur sichergehen, dass ich es richtig verstanden habe, dass calloc und smart ptr keine freunde wären <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/1603219</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1603219</guid><dc:creator><![CDATA[Seikilos]]></dc:creator><pubDate>Thu, 23 Oct 2008 08:11:45 GMT</pubDate></item><item><title><![CDATA[Reply to struct initialisieren? on Thu, 23 Oct 2008 08:14:41 GMT]]></title><description><![CDATA[<p>Seikilos schrieb:</p>
<blockquote>
<p>Dies tu ich in der Tat auch, nur das die init mehr als 100 Zeilen hätte und ich dies gerne vermeiden würde. memset kommt mir da schon zu gute.</p>
<p>Ich wollte nur sichergehen, dass ich es richtig verstanden habe, dass calloc und smart ptr keine freunde wären <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>
</blockquote>
<p>Ne, sind sie nicht. c|malloc + delete ist einem ziemlich schlechte Kombination. Die harmonieren irgendwie nicht. <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/1603223</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1603223</guid><dc:creator><![CDATA[Tachyon]]></dc:creator><pubDate>Thu, 23 Oct 2008 08:14:41 GMT</pubDate></item><item><title><![CDATA[Reply to struct initialisieren? on Thu, 23 Oct 2008 09:16:17 GMT]]></title><description><![CDATA[<p>Seikilos schrieb:</p>
<blockquote>
<p>Ich wollte nur sichergehen, dass ich es richtig verstanden habe, dass calloc und smart ptr keine freunde wären <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>
</blockquote>
<p>Wenn ich mich noch richtig erinnere, so hat die <a href="http://loki-lib.sourceforge.net/html/a00634.html" rel="nofollow">Loki-Bibliothek</a> aber durchaus Smartpointer die man für die alloc-Geschichten &quot;konfigurieren&quot; kann (Bereich Delete policies, Loki::DeleteUsingFree&lt; P &gt;).</p>
<p>Wobei ich die Loki-Bibliothek zumindestens von ihrer Verständlichkeit nicht wirklich gut finde (Ich finde auch das Buch &quot;Modern C++ Design&quot; als zu knapp von den Ausführungen her, und imho hätten auch noch Beispiele aus der Realität gut getan; Zumindestens wäre es dann leichter &quot;verdaulich&quot;).</p>
<p>cu André</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1603260</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1603260</guid><dc:creator><![CDATA[asc]]></dc:creator><pubDate>Thu, 23 Oct 2008 09:16:17 GMT</pubDate></item><item><title><![CDATA[Reply to struct initialisieren? on Thu, 23 Oct 2008 14:35:48 GMT]]></title><description><![CDATA[<p>asc schrieb:</p>
<blockquote>
<p>Seikilos schrieb:</p>
<blockquote>
<p>Ich wollte nur sichergehen, dass ich es richtig verstanden habe, dass calloc und smart ptr keine freunde wären <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>
</blockquote>
<p>Wenn ich mich noch richtig erinnere, so hat die <a href="http://loki-lib.sourceforge.net/html/a00634.html" rel="nofollow">Loki-Bibliothek</a> aber durchaus Smartpointer die man für die alloc-Geschichten &quot;konfigurieren&quot; kann (Bereich Delete policies, Loki::DeleteUsingFree&lt; P &gt;).</p>
<p>Wobei ich die Loki-Bibliothek zumindestens von ihrer Verständlichkeit nicht wirklich gut finde (Ich finde auch das Buch &quot;Modern C++ Design&quot; als zu knapp von den Ausführungen her, und imho hätten auch noch Beispiele aus der Realität gut getan; Zumindestens wäre es dann leichter &quot;verdaulich&quot;).</p>
<p>cu André</p>
</blockquote>
<p>Du erinnerst dich richtig. Im Rahmen der Storage Policy kann man durchaus auch ein free() einbauen.<br />
Was Verständlichkeit etc. angeht kann ich dir aber nicht zustimmen. Es ist zwar Anfangs etwas schwierig die Konzepte zu verinnerlichen die im &quot;täglichen Gebrauch&quot; nicht so häufig vorkommen, aber wenn man das hat ist die Bibliothek nicht komplizierter als andere auch, und das Buch hat durchaus Beispiele, konzentriert sich allerdings auf die Facts statt sich in einen rundum-Sorglos Paket für die Anwendungsbeispiele zu verzetteln...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1603465</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1603465</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Thu, 23 Oct 2008 14:35:48 GMT</pubDate></item></channel></rss>