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.