<?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[Integer overflow]]></title><description><![CDATA[<p>Hallo!<br />
Folgendes Problem:<br />
Bei der Fakultätenrechnung kommt es schnell zu einem integer overflow.<br />
Wie ist es möglich zu prüfungen, ob ein integer overflow stattgefunden hat? ich möchte, dass wenn ein overflow stattgefunden hat, die berechnung gestopt wird und eine fehlermeldung ausgegeben wird. ich muss leider mit dem datentyp integer arbeiten....<br />
ich verlange keine lösung, lediglich nen kleinen denkanstoß <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>
<p>danke!<br />
mfg dennis</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/198142/integer-overflow</link><generator>RSS for Node</generator><lastBuildDate>Thu, 01 Oct 2026 21:24:42 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/198142.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 18 Nov 2007 22:18:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Integer overflow on Sun, 18 Nov 2007 22:18:04 GMT]]></title><description><![CDATA[<p>Hallo!<br />
Folgendes Problem:<br />
Bei der Fakultätenrechnung kommt es schnell zu einem integer overflow.<br />
Wie ist es möglich zu prüfungen, ob ein integer overflow stattgefunden hat? ich möchte, dass wenn ein overflow stattgefunden hat, die berechnung gestopt wird und eine fehlermeldung ausgegeben wird. ich muss leider mit dem datentyp integer arbeiten....<br />
ich verlange keine lösung, lediglich nen kleinen denkanstoß <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>
<p>danke!<br />
mfg dennis</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1405613</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1405613</guid><dc:creator><![CDATA[DennisM]]></dc:creator><pubDate>Sun, 18 Nov 2007 22:18:04 GMT</pubDate></item><item><title><![CDATA[Reply to Integer overflow on Sun, 18 Nov 2007 23:31:09 GMT]]></title><description><![CDATA[<p>Eine Möglichkeit wäre das Ergebnis jeder Multiplikation zu prüfen, ala so:</p>
<pre><code class="language-cpp">template &lt;class T&gt; T checked_multiply(T a, T b)
{
    T x = a * b;
    if ((x / a) != b)
        throw whatever(&quot;integer overflow.&quot;);
    return x;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1405633</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1405633</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Sun, 18 Nov 2007 23:31:09 GMT</pubDate></item><item><title><![CDATA[Reply to Integer overflow on Mon, 19 Nov 2007 15:04:51 GMT]]></title><description><![CDATA[<p>Wird bei einem Overflow nicht automatisch eine Exception ausgelöst?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1405962</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1405962</guid><dc:creator><![CDATA[*D*]]></dc:creator><pubDate>Mon, 19 Nov 2007 15:04:51 GMT</pubDate></item><item><title><![CDATA[Reply to Integer overflow on Mon, 19 Nov 2007 17:06:04 GMT]]></title><description><![CDATA[<p>D schrieb:</p>
<blockquote>
<p>Wird bei einem Overflow nicht automatisch eine Exception ausgelöst?</p>
</blockquote>
<p>schon</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1406037</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1406037</guid><dc:creator><![CDATA[XP*]]></dc:creator><pubDate>Mon, 19 Nov 2007 17:06:04 GMT</pubDate></item><item><title><![CDATA[Reply to Integer overflow on Mon, 19 Nov 2007 17:25:02 GMT]]></title><description><![CDATA[<p>Dann kann man doch einfach einen Exception-Handle einbauen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1406055</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1406055</guid><dc:creator><![CDATA[*D*]]></dc:creator><pubDate>Mon, 19 Nov 2007 17:25:02 GMT</pubDate></item><item><title><![CDATA[Reply to Integer overflow on Mon, 19 Nov 2007 18:22:32 GMT]]></title><description><![CDATA[<p>XP^ schrieb:</p>
<blockquote>
<p>D schrieb:</p>
<blockquote>
<p>Wird bei einem Overflow nicht automatisch eine Exception ausgelöst?</p>
</blockquote>
<p>schon</p>
</blockquote>
<p>Nein, bei einem normalen Integer-Überlauf (bzw. Unterlauf) wird KEINE Exception ausgelöst:</p>
<pre><code class="language-cpp">int x=0;
while(true)
  x++; // Endlos-Schleife
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1406088</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1406088</guid><dc:creator><![CDATA[Th]]></dc:creator><pubDate>Mon, 19 Nov 2007 18:22:32 GMT</pubDate></item><item><title><![CDATA[Reply to Integer overflow on Mon, 19 Nov 2007 18:30:22 GMT]]></title><description><![CDATA[<p>D schrieb:</p>
<blockquote>
<p>Wird bei einem Overflow nicht automatisch eine Exception ausgelöst?</p>
</blockquote>
<p>Nein. Überlauf von vorzeichenbehafteten Integern ist undefiniertes Verhalten - ein Exception (In diesem Forum heißt das immer: C++-Exception, über plattformabhängige Mechanismen brauchen wir hier nicht diskutieren) kann prinzipiell nicht geworfen werden, denn Eceptions entstehen immer nur als Resultat von Funktionsaufrufen bzw. einem throw-Ausdruck - niemals aber als Folge von eingebauten Operatoren (das wäre u.a. im Hinblick auf die unspezifizierte Reihenfolge der Auswertung von Operanden auch nur schwer zu beherrschen). Ein Überlauf vorzeichenloser Integer ist unproblematisch, da dieser modulo-2^n Arithmetik benutzen - das stellt keinen Fehler dar und löst erst recht keine Exception aus.<br />
Folglich ist der einzig standardkonforme Weg (für vorzeichenbehaftete Integer), den Überlauf abzufangen, bevor er ensteht:</p>
<pre><code class="language-cpp">template &lt;class T&gt; T checked_multiply(T a, T b)
{
    return a == 0 || std::numeric_limits&lt;T&gt;::max() / a &gt;= b ? a * b : throw whatever(&quot;integer overflow.&quot;);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1406089</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1406089</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Mon, 19 Nov 2007 18:30:22 GMT</pubDate></item><item><title><![CDATA[Reply to Integer overflow on Mon, 19 Nov 2007 23:55:56 GMT]]></title><description><![CDATA[<p>Ups, den Fall a == 0 hab ich übersehen. Peinlich ... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<p>p.S.:<br />
<a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/6642">@camper</a>: Meinst du damit meine Lösung ist (ausgenommen mal vom fehlenden Test auf a == 0) falsch? Wenn ja würde mich interessieren wo es da ein Problem geben könnte...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1406290</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1406290</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Mon, 19 Nov 2007 23:55:56 GMT</pubDate></item></channel></rss>