<?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++ Datentypen]]></title><description><![CDATA[<p>#include &lt;iostream&gt;<br />
using namespace std;</p>
<p>void main(void)<br />
{</p>
<p>short Zahl;<br />
cin &gt;&gt; Zahl;</p>
<p>if (Zahl &gt; 30000)<br />
{<br />
typedef int Zahl;<br />
}</p>
<p>cout &lt;&lt; Zahl &lt;&lt; endl;<br />
system (&quot;Pause&quot;);<br />
}</p>
<p>Wie ihr seht, versuche ich gerade ein Programm zu optimieren.<br />
Ich will wenn die eingegebene Zahl größer als 30000 den Datentyp automatisch in einen Integer umwandeln. Um Speicherplatz zu spare, bleibt der Datentyp bein einer Eingebenen zahl von weniger als 30000 short.<br />
Wenn ich bei diesem Programm aber eine Zahl eingebe die größer als 30000 ist bleibt der Datentyp trotzdem bei short. Was muss ich änder?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/248662/c-datentypen</link><generator>RSS for Node</generator><lastBuildDate>Wed, 16 Sep 2026 21:07:54 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/248662.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 27 Aug 2009 15:32:06 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to c++ Datentypen on Thu, 27 Aug 2009 15:32:06 GMT]]></title><description><![CDATA[<p>#include &lt;iostream&gt;<br />
using namespace std;</p>
<p>void main(void)<br />
{</p>
<p>short Zahl;<br />
cin &gt;&gt; Zahl;</p>
<p>if (Zahl &gt; 30000)<br />
{<br />
typedef int Zahl;<br />
}</p>
<p>cout &lt;&lt; Zahl &lt;&lt; endl;<br />
system (&quot;Pause&quot;);<br />
}</p>
<p>Wie ihr seht, versuche ich gerade ein Programm zu optimieren.<br />
Ich will wenn die eingegebene Zahl größer als 30000 den Datentyp automatisch in einen Integer umwandeln. Um Speicherplatz zu spare, bleibt der Datentyp bein einer Eingebenen zahl von weniger als 30000 short.<br />
Wenn ich bei diesem Programm aber eine Zahl eingebe die größer als 30000 ist bleibt der Datentyp trotzdem bei short. Was muss ich änder?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1767769</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1767769</guid><dc:creator><![CDATA[c++lernerbrauch hilfe]]></dc:creator><pubDate>Thu, 27 Aug 2009 15:32:06 GMT</pubDate></item><item><title><![CDATA[Reply to c++ Datentypen on Thu, 27 Aug 2009 15:33:07 GMT]]></title><description><![CDATA[<p>Du kannst den Typ einer Variablen nicht ändern.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1767770</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1767770</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Thu, 27 Aug 2009 15:33:07 GMT</pubDate></item><item><title><![CDATA[Reply to c++ Datentypen on Thu, 27 Aug 2009 15:43:24 GMT]]></title><description><![CDATA[<p>volkard schrieb:</p>
<blockquote>
<p>Du kannst den Typ einer Variablen nicht ändern.</p>
</blockquote>
<p>Das ist, wie du bestimmt weisst nicht die ganze Wahrheit. <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>Der statische Typ lässt sich nicht ändern, den dynamischen, welchen wir bei Polymorphen Objekten haben aber sehr wohl.</p>
<pre><code class="language-cpp">struct base
{
};

struct child1 : base
{};

struct child2 : base
{};

..

child1 c1;
child2 c2;

base* b = c1;
if ( ... )
  b = c2;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1767773</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1767773</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Thu, 27 Aug 2009 15:43:24 GMT</pubDate></item><item><title><![CDATA[Reply to c++ Datentypen on Thu, 27 Aug 2009 15:58:17 GMT]]></title><description><![CDATA[<p>drakon schrieb:</p>
<blockquote>
<p>volkard schrieb:</p>
<blockquote>
<p>Du kannst den Typ einer Variablen nicht ändern.</p>
</blockquote>
<p>Das ist, wie du bestimmt weisst nicht die ganze Wahrheit. <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>Es bleibt in Deinem Beispiel ein Zeiger auf base.<br />
Ich weiß auch nicht so recht, was der Dynamische Typ einer Variablen ist.</p>
<p>Edit: Ah, habs nachgelesen.</p>
<pre><code class="language-cpp">int i;
void* p=&amp;i;
</code></pre>
<p>Jetzt hat p den statischen Typ &quot;Zeiger auf void&quot; den dynamischen Typ &quot;int&quot;.</p>
<pre><code class="language-cpp">double d;
int i=reinterpret_cast&lt;int&gt;(&amp;p);
</code></pre>
<p>Jetzt hat i den statischen Typ &quot;int&quot; und den dynamischen Typ &quot;double&quot;.</p>
<p>Faszinierend.</p>
<p>edit2: Auch falsch. Das gilt ja nur bei polymorphen Typen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1767779</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1767779</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Thu, 27 Aug 2009 15:58:17 GMT</pubDate></item><item><title><![CDATA[Reply to c++ Datentypen on Thu, 27 Aug 2009 16:09:42 GMT]]></title><description><![CDATA[<p>c++lernerbrauch hilfe schrieb:</p>
<blockquote>
<p>Wie ihr seht, versuche ich gerade ein Programm zu optimieren.</p>
</blockquote>
<p>Wie wir sehen, versuchst du gerade, C++ auf eine Weise zurechtzubiegen, die dir nicht einmal wirklich eine Optimierung bringt.</p>
<p>Sehr sinnvoll ist das nicht, was du da probierst. Du könntest natürlich über <code>void*</code> eine Frickellösung hinkriegen, mit der du nur den nötigen Speicher für die Zahl anforderst. Bezüglich Optimierung geht der Schuss dann aber gewaltig nach hinten los, da du statt der eingesparten 2 Bytes nun 4 zusätzliche für den Zeiger brauchst und du eine langsame Heap-Allokation hast.</p>
<p>Also kurz gesagt: Nimm ruhig einen <code>int</code> , auch wenn der Wertebereich nicht voll ausgenutzt wird.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1767795</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1767795</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Thu, 27 Aug 2009 16:09:42 GMT</pubDate></item><item><title><![CDATA[Reply to c++ Datentypen on Thu, 27 Aug 2009 18:39:52 GMT]]></title><description><![CDATA[<p>volkard schrieb:</p>
<blockquote>
<p>drakon schrieb:</p>
<blockquote>
<p>volkard schrieb:</p>
<blockquote>
<p>Du kannst den Typ einer Variablen nicht ändern.</p>
</blockquote>
<p>Das ist, wie du bestimmt weisst nicht die ganze Wahrheit. <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>Es bleibt in Deinem Beispiel ein Zeiger auf base.</p>
</blockquote>
<p>Ja. Der statische Typ, aber der dynamische ist der des abgeleiteten Objektes, auf welches er zeigt. Und den kann man ja bekannterweise ändern.</p>
<blockquote>
<p>1.3.3 dynamic type [defns.dynamic.type]<br />
the type of the most derived object (1.8) to which the lvalue denoted by an lvalue expression refers. [Example:<br />
if a pointer (8.3.1) p whose static type is “pointer to class B” is pointing to an object of class D, derived<br />
from B (clause 10), the dynamic type of the expression *p is “D.” References (8.3.2) are treated similarly. ]<br />
The dynamic type of an rvalue expression is its static type.</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/1767872</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1767872</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Thu, 27 Aug 2009 18:39:52 GMT</pubDate></item><item><title><![CDATA[Reply to c++ Datentypen on Thu, 27 Aug 2009 21:39:41 GMT]]></title><description><![CDATA[<p>Weils mir gerade einfällt:</p>
<p>drakon schrieb:</p>
<blockquote>
<pre><code class="language-cpp">struct base
{
};

struct child1 : base
{};

struct child2 : base
{};
</code></pre>
</blockquote>
<pre><code class="language-cpp">child1 c1;
child2 c2;

base* b = &amp;c1;
if ( ... )
  b = &amp;c2;
</code></pre>
<p>was würde decltype hier machen?</p>
<pre><code class="language-cpp">child1 c1; //decltype(c1) == child1
child2 c2; //decltype(c2) == child2

base* b = &amp;c1;
 //decltype(b) == base* ?
 //decltype(*b) == child1 ?
</code></pre>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1767959</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1767959</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Thu, 27 Aug 2009 21:39:41 GMT</pubDate></item><item><title><![CDATA[Reply to c++ Datentypen on Thu, 27 Aug 2009 21:47:40 GMT]]></title><description><![CDATA[<p><code>decltype</code> arbeitet ja auf Kompilierebene, also würde ich sagen, dass es zweimal <code>base*</code> gibt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1767962</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1767962</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Thu, 27 Aug 2009 21:47:40 GMT</pubDate></item><item><title><![CDATA[Reply to c++ Datentypen on Thu, 27 Aug 2009 22:01:47 GMT]]></title><description><![CDATA[<p>drakon schrieb:</p>
<blockquote>
<p><code>decltype</code> arbeitet ja auf Kompilierebene, also würde ich sagen, dass es zweimal <code>base*</code> gibt.</p>
</blockquote>
<p>auch bei <code>decltype(*b)</code> ? Oo</p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1767967</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1767967</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Thu, 27 Aug 2009 22:01:47 GMT</pubDate></item><item><title><![CDATA[Reply to c++ Datentypen on Thu, 27 Aug 2009 22:05:11 GMT]]></title><description><![CDATA[<p>unskilled schrieb:</p>
<blockquote>
<p>drakon schrieb:</p>
<blockquote>
<p><code>decltype</code> arbeitet ja auf Kompilierebene, also würde ich sagen, dass es zweimal <code>base*</code> gibt.</p>
</blockquote>
<p>auch bei <code>decltype(*b)</code> ? Oo</p>
<p>bb</p>
</blockquote>
<p>Ne, sorry. Da würde ich sagen <code>base</code> .</p>
<p>Den tatsächlichen Typen kann man zur Kompilierzeit ja nicht feststellen. (ginge wahrscheinlich mit Typenanalyse zum Teil schon, aber das ist ein anderes Thema.. :))</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1767969</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1767969</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Thu, 27 Aug 2009 22:05:11 GMT</pubDate></item><item><title><![CDATA[Reply to c++ Datentypen on Thu, 27 Aug 2009 22:05:44 GMT]]></title><description><![CDATA[<p>unskilled schrieb:</p>
<blockquote>
<p>auch bei <code>decltype(*b)</code> ? Oo</p>
</blockquote>
<p>ja.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1767970</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1767970</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Thu, 27 Aug 2009 22:05:44 GMT</pubDate></item><item><title><![CDATA[Reply to c++ Datentypen on Fri, 28 Aug 2009 11:00:16 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">struct base {};
struct child1 : base {};
struct child2 : base {};
</code></pre>
<p>unskilled schrieb:</p>
<blockquote>
<p>was würde decltype hier machen?</p>
<pre><code class="language-cpp">child1 c1; //decltype(c1) == child1
child2 c2; //decltype(c2) == child2
base* b = &amp;c1;
 //decltype(b) == base* ?
 //decltype(*b) == child1 ?
</code></pre>
</blockquote>
<pre><code>decltype(b)    steht für base*
decltype((b))  steht für base*&amp;
decltype(*b)   steht für base&amp;
</code></pre>
<p>Es wird zwischen Bezeichner und Ausdruck unterschieden. decltype liefert den deklarierten Typ des Bezeichners oder den &quot;Rückgabetypen&quot; eines Ausdrucks. Andere Beispiele:</p>
<pre><code class="language-cpp">struct foo {
  int j;
};
foo const&amp; f = ...;
</code></pre>
<pre><code>decltype(f)     --&gt; Deklarierter Typ des Bezeichners f ist [b]foo const&amp;[/b]
decltype(f.j)   --&gt; Deklarierter Typ des Bezeichners foo::j ist [b]int[/b]
decltype((f.j)) --&gt; &quot;Typ des Ausdrucks&quot; f.j ist [b]int const&amp;[/b]
</code></pre>
<p>Da fragt man sich zunächst, ob das wirklich alles so sinnvoll ist. Ich habe mich aber inzwischen damit angefreundet.</p>
<p>(Angaben ohne Gewähr)</p>
<p>edit: Ich habe es nochmal nachgeguckt. Es gibt vier Fälle.<br />
(1) <em>nicht-geklammerten</em> Bezeichner oder Elementzugriff --&gt; decltype liefert den deklarierten Typ.<br />
(2) andernfalls, Funktionsaufruf --&gt; decltype liefert den Rückgabetyp der Funktion<br />
(3) andernfalls, Lvalue-Ausdruck --&gt; decltype liefert eine entsprechende Lvalue-Referenz.<br />
(4) andernfalls --&gt; decltype liefert den Typ des Ausdrucks.</p>
<p>Gruß,<br />
SP</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1768140</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1768140</guid><dc:creator><![CDATA[Sebastian Pizer]]></dc:creator><pubDate>Fri, 28 Aug 2009 11:00:16 GMT</pubDate></item><item><title><![CDATA[Reply to c++ Datentypen on Fri, 28 Aug 2009 11:21:00 GMT]]></title><description><![CDATA[<p>Danke SP : &gt;</p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1768186</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1768186</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Fri, 28 Aug 2009 11:21:00 GMT</pubDate></item></channel></rss>