ID Number: Q60747
6.00 6.00a 6.00ax | 6.00 6.00a
MS-DOS | OS/2
buglist6.00 buglist6.00a buglist6.00ax fixlist7.00
Summary:
SYMPTOMS
When using the quick compile (/qc) option, the Microsoft C Compiler
versions 6.0, 6.0a, and 6.0ax incorrectly zero-extend one's
complement operations that result in negative integers, rather than
sign-extending them.
RESOLUTION
One possible solution is to typecast the one's complement to an int
before assigning it to a long [for example, l=(int)~1023].
STATUS
Microsoft has confirmed this to be a problem in C versions 6.0,
6.0a, and 6.0ax. This problem was corrected in C/C++ version 7.0.
More Information:
When compiled with the /qc option, the sample code below produces a
value of 64512 for l. When compiled with the full optimizing compiler,
the correct result of -1024 is produced for l.
In ANSI C, the constant 1023 is represented as an integer. The one's
complement of 1023 (-1024) should remain an integer, and when promoted
to a long, this integer should then be sign-extended, preserving the
value. With /qc, 1023 is stored as an integer; however, it doesn't
sign-extend the one's complement as it should.
Sample Code
-----------
/* Compile options needed: /qc
*/
#include<stdio.h>
void main(void)
{
long l;
l=~1023; /* One's complement not properly extended */
printf("%ld\n",l);
}
Additional reference words: 6.00 6.00a 6.00ax