D
Dave Thompson
One of two correct values in C89/90 (and C95) and the only one in C99.If signed int on your platform can hold all the values of an unsigned
short, 'a' and 'b' will be promoted to signed int for the subtraction.
Equivalent to: <snip>
Right.
The expression inside the parentheses evaluates to (int)-7. One of
the two possible correct values for -7 % 8 allowed prior to C99 is -7.
Prior to C89/90, I'm not sure if % was specified that precisely.
(USHRT_MAX + 1) - 7, in this case 0x10000 - 7. In mathematicallyWhen you assign (int)-7 to an unsigned short, the behavior of unsigned
types with out of range values occurs. (int)-7 is converted to
USHRT_MAX - 7. For a 16-bit unsigned short, this is 0xffff - 7, which
equals 0xfff9.
correct arithmetic, not necessarily C or machine arithmetic.
<snip rest>
- David.Thompson1 at worldnet.att.net