Re: Pointers gone mad!

Tech-Archive recommends: Fix windows errors by optimizing your registry



"Robby" <Robby@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:12360E4A-FC84-46C6-93F7-1AE64A06B7FA@xxxxxxxxxxxxx
But I was meaning to ask you how do we interpret this line:

int carry = (*A0 > 255 - INCBY);

The condition is equivalent to (A0 + INCBY > 255), that is, "if I add
INCBY to A0, it will overflow". I write the condition as (A0 > 255 -
INCBY) so that there's no overflow while evaluating the condition
itself. Since INCBY is in the range [0, 255], 255 - INCBY is safe. If
A0+INCBY does in fact overflow, you have to increment A1 (that's called
a carry - again, recall your elementary school days), and if that too
overflows, then you need to increment A2.

If you have difficulty remembering long addition pen-and-paper
algorithm, here's a refresher:

http://en.wikipedia.org/wiki/Carry_%28arithmetic%29

What is going on here, are you doing the subtraction first and if its
less than *A0, it gets assigned to carry?

carry just gets a boolean flag, 0 or 1 (condition false or condition
true, correspondingly). C doesn't have a dedicated bool type.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


.



Relevant Pages