subtraction between unsigned ints

Norman Diamond diamond at csl.sony.co.jp
Wed Sep 13 20:16:16 AEST 1989


Someone asked:

>>>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?

I answered:

>>It always has been unsigned, even in K&R days.  pANS says that the
>>result must wrap around modulo some power of 2; this was not required
>>by K&R but surely always occured.

In article <12570024 at hpclwjm.HP.COM> walter at hpclwjm.HP.COM (Walter Murray) writes:

>I think it was required by K&R.  See Appendix A, section 6.5, in the
>first edition (page 184).

That section specifies conversion from [signed] int to unsigned int.
It does not specify the result of subtraction.

Hmm, this raises a new question.  Someone who had the good fortune to
receive service from Global Engineering Documents, please kindly answer:

Does the standard specify the same conversion as K&R-1 did?  Or is this
another quiet change?  On a 1's complement machine, K&R-1 required more
computation than just a move instruction.  Do the pants impose the same
requirement?

--
-- 
Norman Diamond, Sony Corporation (diamond at ws.sony.junet)
  The above opinions are inherited by your machine's init process (pid 1),
  after being disowned and orphaned.  However, if you see this at Waterloo or
  Anterior, then their administrators must have approved of these opinions.



More information about the Comp.std.c mailing list