Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!ucsd!swrinde!cs.utexas.edu!uunet!kddlab!titcca!sragwa!wsgw!socslgw!diamond
From: diamond@csl.sony.co.jp (Norman Diamond)
Newsgroups: comp.std.c
Subject: Re: subtraction between unsigned ints
Message-ID: <10808@riks.csl.sony.co.jp>
Date: 6 Sep 89 05:54:52 GMT
References: 
Reply-To: diamond@riks. (Norman Diamond)
Distribution: comp
Organization: Sony Computer Science Laboratory Inc., Tokyo, Japan
Lines: 37

In article  kuro@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?

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.

>I am talking about this situation like:
>	unsigned int	u, v;
>	long int	x;

Well, that's not quite what you were talking about.  You didn't say,
but sort of implied, that you wanted to know the result when it was
the same size as the operands.  But let's continue.

>	u=3; v=5;
>	x=u-v;
>
>Is x guranteed to be -2?

If long int is the same size as unsigned int, then the big number that
results from subtraction will become signed.  On a two's-complement
machine, yes the result will be -2.

If long int is longer than unsigned int, then the big number that
results from subtraction will remain a big number.

--
-- 
Norman Diamond, Sony Corporation (diamond@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.