ID Number: Q60538
3.00 3.10 3.11 3.14 | 3.00 3.10 3.11 3.12 3.50
MS-DOS | OS/2
buglist3.11 buglist3.12 buglist3.14 buglist3.50
Summary:
When casting an unsigned int preceded by the unary minus operator to a
long int, the expression evaluator in CodeView versions 3.0, 3.1,
3.11, 3.12, 3.14, and 3.5 may behave differently than the C version
6.0, 6.0a, and 6.0ax compilers. The difference in the resulting values
is based on the way the unary minus sign is extended in the type
conversion.
More Information:
In the sample code below, an unsigned long value (p) is preceded by a
unary minus and cast to a long value, which is stored in l. In C, the
value 65511 is assigned to l after the cast when p is 25. In CodeView,
putting a watch on l displays 65511, but putting a watch on the
expression
(long)(-p)
displays the value -25. The watch expression is identical to the code
but the results are different. The expression evaluator seems to
represent -p as a signed integer, sign-extending it to a long, rather
than representing -p as an unsigned integer and then zero-extending it
to a long.
Microsoft has confirmed this to be a problem in CodeView versions 3.0,
3.1, 3.11, 3.12, 3.14, and 3.5. We are researching this problem and
will post new information here as it becomes available.
Sample Code
------------
/* Compile options needed: /Zi /Od
*/
unsigned p=25;
long l;
void main(void)
{
l=(long)(-p);
}
Additional reference words: buglist3.00 buglist3.10 3.00 3.10
3.50 6.00 6.00a 6.00ax