<?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[Frage zu double (im Makro)]]></title><description><![CDATA[<p>Hallo,<br />
wenn ich beispielsweise folgendes Makro schreibe:</p>
<pre><code class="language-cpp">#define P3(a) ((a) * (a) * (a))
</code></pre>
<p>Ist der Typ der Zahl, die zurückgegeben wird, immer double?</p>
<p>Wenn ich das schreibe:</p>
<pre><code class="language-cpp">double r, oflaeche, vol;
cout &lt;&lt; &quot;Geben Sie den Radius der Kugel ein:&quot;;
cin &gt;&gt; r;

oflaeche=4 * PI * P2(r);
vol = 4.0/3.0 * PI * P3(r); //Fehler, wenn ich 4/4 schreibe
</code></pre>
<p>Warum muss ich 4.0 und 3.0 schreiben? Ich komme aus der Welt von Borland und da ist das nicht so. 4 ist doch 4.0.</p>
<p>Vielen Dank<br />
lg, freakC++</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/247947/frage-zu-double-im-makro</link><generator>RSS for Node</generator><lastBuildDate>Thu, 17 Sep 2026 08:02:25 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/247947.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 17 Aug 2009 19:11:40 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Frage zu double (im Makro) on Mon, 17 Aug 2009 19:11:40 GMT]]></title><description><![CDATA[<p>Hallo,<br />
wenn ich beispielsweise folgendes Makro schreibe:</p>
<pre><code class="language-cpp">#define P3(a) ((a) * (a) * (a))
</code></pre>
<p>Ist der Typ der Zahl, die zurückgegeben wird, immer double?</p>
<p>Wenn ich das schreibe:</p>
<pre><code class="language-cpp">double r, oflaeche, vol;
cout &lt;&lt; &quot;Geben Sie den Radius der Kugel ein:&quot;;
cin &gt;&gt; r;

oflaeche=4 * PI * P2(r);
vol = 4.0/3.0 * PI * P3(r); //Fehler, wenn ich 4/4 schreibe
</code></pre>
<p>Warum muss ich 4.0 und 3.0 schreiben? Ich komme aus der Welt von Borland und da ist das nicht so. 4 ist doch 4.0.</p>
<p>Vielen Dank<br />
lg, freakC++</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1762561</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1762561</guid><dc:creator><![CDATA[freakC++]]></dc:creator><pubDate>Mon, 17 Aug 2009 19:11:40 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu double (im Makro) on Mon, 17 Aug 2009 19:14:18 GMT]]></title><description><![CDATA[<p>freakC++ schrieb:</p>
<blockquote>
<p>4 ist doch 4.0.</p>
</blockquote>
<p>Nö.<br />
4 ist ein int.<br />
4/3==1<br />
int/int==int</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1762562</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1762562</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Mon, 17 Aug 2009 19:14:18 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu double (im Makro) on Mon, 17 Aug 2009 19:15:01 GMT]]></title><description><![CDATA[<p>aber ich habe doch als double deklariert...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1762563</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1762563</guid><dc:creator><![CDATA[freakC++]]></dc:creator><pubDate>Mon, 17 Aug 2009 19:15:01 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu double (im Makro) on Mon, 17 Aug 2009 19:16:54 GMT]]></title><description><![CDATA[<p>freakC++ schrieb:</p>
<blockquote>
<p>Ist der Typ der Zahl, die zurückgegeben wird, immer double?</p>
</blockquote>
<p>Es ist nichtmal gesagt, dass es überhaupt eine Zahl ist. Makros sind reine Textersetzung. Wenn es also irgendein Typ ist, der einen operator* überladen hat, dann könnte da <em>irgendwas</em> rauskommen, je nachdem wie der operator deklariert ist. Im Fall von 4/4 handelt es sich um ints, und da gibt int * int * int = int.</p>
<p>Mach statt des Makros einfach eine Templatefunktion, die ist typsicher.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1762564</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1762564</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Mon, 17 Aug 2009 19:16:54 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu double (im Makro) on Mon, 17 Aug 2009 19:17:35 GMT]]></title><description><![CDATA[<p>freakC++ schrieb:</p>
<blockquote>
<p>aber ich habe doch als double deklariert...</p>
</blockquote>
<p>Nö.<br />
Du berechnest erst 4/3 und das ist 1. Dann erst weist Du die 1 einem double zu.</p>
<p>vol = 4/3 * PI * P3(r); //fehler</p>
<p>vol = 4 * PI * P3(r) / 3 ; //oh, geht!</p>
<p>weil 4 / 3 -&gt; int</p>
<p>aber 4 * PI -&gt; double</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1762565</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1762565</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Mon, 17 Aug 2009 19:17:35 GMT</pubDate></item></channel></rss>