<?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[Speicherplatz und struct]]></title><description><![CDATA[<p>hallo,</p>
<p>ich habe folgendes Problem und zwar wirft der folgende code beim Aufruf von free immer eine Ausnahme und ich weiss nicht warum.</p>
<pre><code class="language-cpp">#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;

struct Filme
{
	char Name[20];
	char Rate[20];
	bool test;
};

typedef struct Filme Film;

int main()
{
	Film *film;

	film = (Film*) calloc(1, sizeof(Film));

	strcpy(film-&gt;Name, &quot;Terminator&quot;);
	strcpy(film-&gt;Rate, &quot;10&quot;);

	printf(&quot;%s %s&quot;, film-&gt;Name, film-&gt;Rate);

	film = (Film*) realloc(film, sizeof(Film));

	strcpy(film[1].Name, &quot;Sieben&quot;);
	strcpy(film[1].Rate, &quot;9&quot;);

	printf(&quot;%s %s&quot;, film[1].Name, film[1].Rate);

	free(film);

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/119637/speicherplatz-und-struct</link><generator>RSS for Node</generator><lastBuildDate>Sat, 22 Aug 2026 00:18:53 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/119637.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 03 Sep 2005 15:10:55 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Speicherplatz und struct on Sat, 03 Sep 2005 15:10:55 GMT]]></title><description><![CDATA[<p>hallo,</p>
<p>ich habe folgendes Problem und zwar wirft der folgende code beim Aufruf von free immer eine Ausnahme und ich weiss nicht warum.</p>
<pre><code class="language-cpp">#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;

struct Filme
{
	char Name[20];
	char Rate[20];
	bool test;
};

typedef struct Filme Film;

int main()
{
	Film *film;

	film = (Film*) calloc(1, sizeof(Film));

	strcpy(film-&gt;Name, &quot;Terminator&quot;);
	strcpy(film-&gt;Rate, &quot;10&quot;);

	printf(&quot;%s %s&quot;, film-&gt;Name, film-&gt;Rate);

	film = (Film*) realloc(film, sizeof(Film));

	strcpy(film[1].Name, &quot;Sieben&quot;);
	strcpy(film[1].Rate, &quot;9&quot;);

	printf(&quot;%s %s&quot;, film[1].Name, film[1].Rate);

	free(film);

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/864269</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/864269</guid><dc:creator><![CDATA[k-man]]></dc:creator><pubDate>Sat, 03 Sep 2005 15:10:55 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherplatz und struct on Sat, 03 Sep 2005 15:18:24 GMT]]></title><description><![CDATA[<p>Weil du Speicherplatz für einen allozierst, aber in den zweiten schreibst, vielleicht?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/864278</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/864278</guid><dc:creator><![CDATA[Ringding]]></dc:creator><pubDate>Sat, 03 Sep 2005 15:18:24 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherplatz und struct on Sat, 03 Sep 2005 15:36:57 GMT]]></title><description><![CDATA[<p>ich schreibe in den ersten,</p>
<pre><code class="language-cpp">strcpy(film-&gt;Name, &quot;Terminator&quot;);
	strcpy(film-&gt;Rate, &quot;10&quot;);
</code></pre>
<p>erweitere dann den platz</p>
<pre><code class="language-cpp">film = (Film*) realloc(film, sizeof(Film));
</code></pre>
<p>und schreibe noch in den 2.</p>
<pre><code class="language-cpp">strcpy(film[1].Name, &quot;Sieben&quot;);
	strcpy(film[1].Rate, &quot;9&quot;);
</code></pre>
<p>oder?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/864286</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/864286</guid><dc:creator><![CDATA[k-man]]></dc:creator><pubDate>Sat, 03 Sep 2005 15:36:57 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherplatz und struct on Sat, 03 Sep 2005 15:41:12 GMT]]></title><description><![CDATA[<p>-&gt; Man soll in C++ new/delete und überhaupt kein realloc verwenden <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="🙂"
    /><br />
-&gt; Wenn realloc dann richtig, der zweite Parameter gibt den neuen *insgesamten* Platz an, nicht die Differenz zur alten Größe</p>
<p>MfG SideWinder</p>
]]></description><link>https://www.c-plusplus.net/forum/post/864288</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/864288</guid><dc:creator><![CDATA[SideWinder]]></dc:creator><pubDate>Sat, 03 Sep 2005 15:41:12 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherplatz und struct on Sat, 03 Sep 2005 15:41:40 GMT]]></title><description><![CDATA[<p>realloc(film, sizeof(Film) * 2);</p>
]]></description><link>https://www.c-plusplus.net/forum/post/864289</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/864289</guid><dc:creator><![CDATA[??????????]]></dc:creator><pubDate>Sat, 03 Sep 2005 15:41:40 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherplatz und struct on Sat, 03 Sep 2005 15:42:44 GMT]]></title><description><![CDATA[<p>ah ok danke,</p>
<p>Ich hab realloc falsch verstanden, dachte der 2. parameter ist die größe um die der speicherplatz erweitert werden soll und nich die neue gesamt größe.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/864291</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/864291</guid><dc:creator><![CDATA[k-man]]></dc:creator><pubDate>Sat, 03 Sep 2005 15:42:44 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherplatz und struct on Sat, 03 Sep 2005 20:11:14 GMT]]></title><description><![CDATA[<p>Aus den man-pages:</p>
<blockquote>
<p>void *realloc(void *ptr, size_t size);</p>
<p>DESCRIPTION<br />
[...]</p>
<p>realloc() changes the size of the memory block pointed to<br />
by ptr to size bytes. The contents will be unchanged to<br />
the minimum of the old and new sizes; newly allocated mem­<br />
ory will be uninitialized. If ptr is NULL, the call is<br />
equivalent to malloc(size); if size is equal to zero, the<br />
call is equivalent to free(ptr). Unless ptr is NULL, it<br />
must have been returned by an earlier call to malloc(),<br />
calloc() or realloc().</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/864377</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/864377</guid><dc:creator><![CDATA[MBCS-CITP]]></dc:creator><pubDate>Sat, 03 Sep 2005 20:11:14 GMT</pubDate></item></channel></rss>