This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Unsigned short subtraction

I don't know what the ANSI/ISO C standard says about this, but I would expect the if block in the example below to be executed when a is 0 and b is 65535:

/* a and b are unsigned short (16 bits). */

if( (a - b) < 10)
{
    do something
}

The block is not executed because the comparison of (a - b) with 10 is done without first resetting the upper 16 bits of the result to 0 (actually comparing two 32 bit unsigned int). Same problem with unsigned char. Sauli

0