Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Integer Overflow

Thread Tools

Integer Overflow

Michael Press
Posts: n/a
In article <(E-Mail Removed)>,
Keith Thompson <(E-Mail Removed)> wrote:

> Right. We've argued that because it happens to be true. See C99
> 6.2.5p9:
> A computation involving unsigned operands can never overflow,
> because a result that cannot be represented by the resulting
> unsigned integer type is reduced modulo the number that is one
> greater than the largest value that can be represented by the
> resulting type.
> Informally, it's reasonable to refer to what happens when the result
> of an unsigned operation won't fit in the target type as "overflow".
> The point is that the standard very specifically *doesn't* refer
> to it as "overflow".
> If you don't like the way the standard uses, or doesn't use,
> the term "overflow", that's fine. I'm not sure I like it myself.
> All I'm doing is pointing out what the standard actually says.

There is little to like or dislike. The usage and
definitions are well established and effective.
Overflow only matters for 2's complement arithmetic.

C is carry out of the high bit of a word.
R is carry into the high bit of a word.
O is overflow.
O = C ^ R

Consider four bit words.
ADD 1000 1111 -> 0111 C R V
ADD 0100 0100 -> 1000 C R V
_ _ _
ADD 0100 0011 -> 0111 C R V
ADD 1100 1100 -> 1000 C R V
NEG 1000 -> 1000 C R V

When the bit patterns are interpreted as unsigned integers
only carry matters.

Michael Press
Reply With Quote
Posts: n/a
On 28 Dez. 2010, 13:12, Malcolm McLean
<(E-Mail Removed)> wrote:
> On Dec 28, 10:13*am, arnuld <(E-Mail Removed)> wrote:> WANTED: How to handle integer overflows (and overflows in general)
> > NOTE: Came to think of this exercise because of this article that claims
> > "Nearly all binary searches and mergesorts are broken".

> Normally it's inappropriate for general-purpose logic code to have to
> worry about overflow.
> The real answer is to join the campaign for 64 bit ints. Searchable
> arrays of real data aren't going to go above 64 bits any time soon, so
> the problem is eliminated.

Computations with 64 bit ints can overflow as computations
with 32 bit ints.

Georg Peter
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
integer or long overflow... deancoo C++ 11 03-05-2005 11:13 PM
integer overflow Ashutosh Iddya C Programming 25 04-24-2004 06:16 PM
hhow to detect overflow in integer calculation John Black C++ 1 04-15-2004 05:28 AM
unsigned integer overflow behaviour bartek C++ 3 02-06-2004 09:47 PM
Integer overflow Enrico 'Trippo' Porreca C Programming 9 08-24-2003 10:24 AM