|
-
May 7th, 2004, 11:19 AM
#1
Unsigned numbers: am I correct in my understanding?
Code Gurus,
I ran into a bug which was at first very hard to detect.
I figured it out later on but I want to make sure my assumption is correct about this problem.
Let's say we have an unsigned number
unsigned int x = 10;
int y = 20;
Let's say we have the code:
if( (x - y) < 0 )
{
// x - y is less than 0
}else
{
// x - y is greater than 0
}
This code will never enter into the if-block statement.
Why?
My assumption is that the terms (x - y) as a whole term is
evaluating as an unsigned number thus the value is greater than zero.
Am I correct in my understanding here?
What is going on?
Thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|