The following code works properly in the release mode of VC++2005,
but in debug mode, an extra bit is set:
unsigned long long x, y;
double d;
unsigned long* ptr;
x = 0x7FF7000000000000;
d = *(double*)&x;
y = *(unsigned long long*)&d;
ptr = (unsigned long*)&x;
printf("x = 0x%08x %08x\n", ptr[0], ptr[1]);
ptr = (unsigned long*)&y;
printf("y = 0x%08x %08x\n", ptr[0], ptr[1]);
In debug mode, y comes out as 0x7FFF000000000000.
If you try 0x7FF1000000000000, you will get 0x7FF9000000000000.
Again only in debug mode. I checked the assembly file:
; 19 : x = 0x7ff7000000000000;
mov DWORD PTR _x$[ebp], 0
mov DWORD PTR _x$[ebp+4], 2146893824 ; 7ff70000H
; 20 : d = *(double*)&x;
fld QWORD PTR _x$[ebp]
fstp QWORD PTR _d$[ebp]
; 21 : y = *(unsigned long long*)&d;
mov eax, DWORD PTR _d$[ebp]
mov DWORD PTR _y$[ebp], eax
mov ecx, DWORD PTR _d$[ebp+4]
mov DWORD PTR _y$[ebp+4], ecx
I don't see anything unusual.
This works fine in VC6. VC6 generates assembly code with 'mov' instead
of 'fld/fstp'
instructions.
I know it's not a typical thing to do, but this is an important
technique
for some low level language implementation. Could someone from
Microsoft
respond?