<?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[C++ C Cast Problem]]></title><description><![CDATA[<p>Habe eine C Datei und möchte die in mein C++ Projekt einbinden.</p>
<p>Jetzt hab ich ein Problem:</p>
<pre><code>spline.control_point =  calloc(...)
</code></pre>
<p>von void* kann er nicht auf &quot;dxf_spline_::control_point_t*&quot; konvertieren</p>
<pre><code>typedef struct dxf_spline_{
    union control_point_t{
    fpoint3_t c3;
    fpoint2_t c2;
  } *control_point;
}dxf_spline_t;
</code></pre>
<p>Wie muss ich casten?<br />
= (union control_point_t*) calloc<br />
funktioniert nicht</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/214159/c-c-cast-problem</link><generator>RSS for Node</generator><lastBuildDate>Tue, 13 Oct 2026 20:51:59 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/214159.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 26 May 2008 11:04:00 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to C++ C Cast Problem on Mon, 26 May 2008 11:04:00 GMT]]></title><description><![CDATA[<p>Habe eine C Datei und möchte die in mein C++ Projekt einbinden.</p>
<p>Jetzt hab ich ein Problem:</p>
<pre><code>spline.control_point =  calloc(...)
</code></pre>
<p>von void* kann er nicht auf &quot;dxf_spline_::control_point_t*&quot; konvertieren</p>
<pre><code>typedef struct dxf_spline_{
    union control_point_t{
    fpoint3_t c3;
    fpoint2_t c2;
  } *control_point;
}dxf_spline_t;
</code></pre>
<p>Wie muss ich casten?<br />
= (union control_point_t*) calloc<br />
funktioniert nicht</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1516850</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1516850</guid><dc:creator><![CDATA[Sisko86]]></dc:creator><pubDate>Mon, 26 May 2008 11:04:00 GMT</pubDate></item><item><title><![CDATA[Reply to C++ C Cast Problem on Mon, 26 May 2008 11:09:22 GMT]]></title><description><![CDATA[<p>Sisko86 schrieb:</p>
<blockquote>
<p>Habe eine C Datei und möchte die in mein C++ Projekt einbinden.</p>
</blockquote>
<p>Nachfrage: Möchtest du sie einbinden, oder kann sie auch angepasst werden?</p>
<p>Für das einbinden sieht es glaube ich so aus (arbeite nur an DLL-Schnittstellen mit C, daher nicht ganz 100% sicher):</p>
<pre><code class="language-cpp">extern &quot;C&quot;
{
  #include &quot;meineCDatei.h&quot;
}
</code></pre>
<p>Vielleicht funktioniert es damit.</p>
<p>cu André</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1516853</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1516853</guid><dc:creator><![CDATA[asc]]></dc:creator><pubDate>Mon, 26 May 2008 11:09:22 GMT</pubDate></item><item><title><![CDATA[Reply to C++ C Cast Problem on Mon, 26 May 2008 11:23:07 GMT]]></title><description><![CDATA[<p>Mach es wie asc sagte und konpilier die C-Übersetzungseinheit mit einem C-Compiler. Ansonsten müsstest Du wahrscheinlich noch mehr Code nach C++ umschreiben. Dann müsste folgender Cast funktionieren:</p>
<pre><code class="language-cpp">spline.control_point = static_cast&lt;dxf_spline_::control_point_t*&gt;(calloc(...));
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1516860</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1516860</guid><dc:creator><![CDATA[Konrad Rudolph]]></dc:creator><pubDate>Mon, 26 May 2008 11:23:07 GMT</pubDate></item><item><title><![CDATA[Reply to C++ C Cast Problem on Mon, 26 May 2008 11:33:20 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">static_cast&lt;dxf_spline_t::control_point*&gt;(calloc(...))
</code></pre>
<p>besser noch</p>
<pre><code class="language-cpp">new dxf_spline_t::control_point(); //bzw.
new dxf_spline_t::control_point[..]();
</code></pre>
<p>Strenggenommen ist das nicht ganz äquivalent zu calloc - es bildet eher noch besser die Intention ab.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1516866</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1516866</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Mon, 26 May 2008 11:33:20 GMT</pubDate></item><item><title><![CDATA[Reply to C++ C Cast Problem on Mon, 26 May 2008 11:43:42 GMT]]></title><description><![CDATA[<p>camper schrieb:</p>
<blockquote>
<p>...<br />
besser noch</p>
<pre><code class="language-cpp">new dxf_spline_t::control_point(); //bzw.
new dxf_spline_t::control_point[..]();
</code></pre>
<p>...</p>
</blockquote>
<p>Dann aber bei der Freigabe natürlich delete bzw. delete[] nicht vergessen (statt free).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1516871</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1516871</guid><dc:creator><![CDATA[asc]]></dc:creator><pubDate>Mon, 26 May 2008 11:43:42 GMT</pubDate></item><item><title><![CDATA[Reply to C++ C Cast Problem on Mon, 26 May 2008 11:46:39 GMT]]></title><description><![CDATA[<p>extern &quot;C&quot; Funktioniert irgendwie nicht<br />
Es wird nicht als C kompiliert.</p>
<p>Kann ich die C Datei so anpassen, dass sie evtl. auch wieder als C kompiliert werden kann. new und static_cast fallen somit aus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1516876</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1516876</guid><dc:creator><![CDATA[Sisko86]]></dc:creator><pubDate>Mon, 26 May 2008 11:46:39 GMT</pubDate></item><item><title><![CDATA[Reply to C++ C Cast Problem on Mon, 26 May 2008 11:53:24 GMT]]></title><description><![CDATA[<p>Sisko86 schrieb:</p>
<blockquote>
<p>extern &quot;C&quot; Funktioniert irgendwie nicht<br />
Es wird nicht als C kompiliert.</p>
</blockquote>
<p>Klar. 'extern &quot;C&quot;' hat nichts damit zu tun, wie die Dateien kompiliert werden. Es geht hierbei nur darum, C++ das Finden der Symbole zu ermöglichen.</p>
<p>Aber Dein C-Code wird ja wohl (hoffentlich!) in eine h- und eine c-Datei aufgeteilt sein. Nur die h-Datei wird per #include eingefügt, die c-Datei hingegen nicht. *Diese* Datei musst Du (im Gegensatz zum Rest) mit einem C-Compiler kompilieren. Das geschieht evtl. auch nicht automatisch sondern muss von Dir speziell angegeben werden.</p>
<p>Auf welchem System arbeitest Du? Das ist seehr unterschiedlich je nach verwendeter Plattform. Wenn Du mit GCC/make arbeitest, sollte der korrekte Compiler allerdings normalerweise automatisch gewählt werden. Unter Visual Studio hingegen geht das so einfach nicht (wie es dort geht, weiß ich nicht).</p>
<blockquote>
<p>Kann ich die C Datei so anpassen, dass sie evtl. auch wieder als C kompiliert werden kann. new und static_cast fallen somit aus.</p>
</blockquote>
<p>Na ja, statt des C++-Casts kann zur Not auch ein C-Cast verwendet werden. Dein Typenname war halt nur unvollständig, daher hat der Cast nicht funktioniert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1516878</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1516878</guid><dc:creator><![CDATA[Konrad Rudolph]]></dc:creator><pubDate>Mon, 26 May 2008 11:53:24 GMT</pubDate></item><item><title><![CDATA[Reply to C++ C Cast Problem on Mon, 26 May 2008 12:03:21 GMT]]></title><description><![CDATA[<p>Hab den C Cast geändert, jetzt Funktionierts<br />
(dxf_spline_::control_point_t*)<br />
Auf diese Schreibweise wäre ich nicht gekommen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1516882</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1516882</guid><dc:creator><![CDATA[Sisko86]]></dc:creator><pubDate>Mon, 26 May 2008 12:03:21 GMT</pubDate></item></channel></rss>