subtraction between unsigned ints

Henry Spencer henry at utzoo.uucp
Thu Sep 7 01:34:07 AEST 1989


In article <KURO.89Sep5111940 at shochu.Sun.Com> kuro at shochu.Sun.Com (Teruhiko Kurosaka - Sun Intercon) writes:
>Does pANSI defines the datatype of the result of subtraction
>between unsigned integers?  Would it be also unsigned?  Then
>what would be the result of subtraction of a number from a
>smaller number? ...

Unsigned - unsigned gives unsigned.  Unsigned arithmetic is done modulo the
type size, roughly speaking, so carries and borrows off the top end are
ignored.  The value of "(unsigned)3 - (unsigned)5" depends on how big the
unsigned type is, but on a 16-bit machine it's probably (unsigned)65534.
-- 
V7 /bin/mail source: 554 lines.|     Henry Spencer at U of Toronto Zoology
1989 X.400 specs: 2200+ pages. | uunet!attcan!utzoo!henry henry at zoo.toronto.edu



More information about the Comp.std.c mailing list