Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > Re: Subtracting...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 12 Topic 26169 of 27679
Post > Topic >>

Re: Subtracting unsigned entities

by Ben Pfaff <blp@[EMAIL PROTECTED] > May 12, 2008 at 03:26 PM

fred.l.kleinschmidt@[EMAIL PROTECTED]
 writes:

> If one knows that x and y are unsigned integers (of unknown size -
> they may be short, int, long, long long), what is the most ****table
> way to determine their difference?
>
> If x is smaller than y, then x-y is negative.

Mathematically, yes.  But in C, the difference of two values of
type unsigned int is always nonnegative.

> A naive approach is
>    if ( x > y ) {
>       ...
>    }
>
> but a compiler may code (x>y) as  (x-y > 0).

No, the compiler is obliged to produce the correct result.
-- 
"The way I see it, an intelligent person who disagrees with me is
 probably the most im****tant person I'll interact with on any given
 day."
--Billy Chambless
 




 12 Posts in Topic:
Subtracting unsigned entities
fred.l.kleinschmidt@[EMAI  2008-05-12 15:18:14 
Re: Subtracting unsigned entities
Richard Heathfield <rj  2008-05-12 22:24:45 
Re: Subtracting unsigned entities
Ben Pfaff <blp@[EMAIL   2008-05-12 15:26:55 
Re: Subtracting unsigned entities
=?ISO-8859-1?Q?Tom=E1s_=D  2008-05-12 15:44:11 
Re: Subtracting unsigned entities
Bart <bc@[EMAIL PROTEC  2008-05-12 15:58:10 
Re: Subtracting unsigned entities
Peter Nilsson <airia@[  2008-05-12 20:00:00 
Re: Subtracting unsigned entities
Chris Dollin <chris.do  2008-05-13 10:15:45 
Re: Subtracting unsigned entities
fred.l.kleinschmidt@[EMAI  2008-05-13 07:50:27 
Re: Subtracting unsigned entities
Eric Sosman <Eric.Sosm  2008-05-13 11:03:17 
Re: Subtracting unsigned entities
Chris Dollin <chris.do  2008-05-13 16:11:24 
Re: Subtracting unsigned entities
=?iso-8859-1?Q?=D8yvind_R  2008-05-13 22:55:41 
Re: Subtracting unsigned entities
Harald van =?UTF-8?b?RMSz  2008-05-13 23:16:38 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Oct 11 21:21:34 CDT 2008.