473,395 Members | 1,502 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

long long and double pointer manipulation problem

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?

Mar 27 '06 #1
0 902

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

31
by: Jamie Burns | last post by:
Hello, I am writing a client / server application. There is 1 server, and many clients. The server processes requests from each client, and typically creates and manipulates C++ objects on their...
7
by: Master of C++ | last post by:
Hello Folks, I have a programming dilemma with templates and "genericity". I can think of a few solutions, but I am not sure which one is the best in terms of genetic C++ style. Any suggestions...
8
by: sugaray | last post by:
Hi, I just came upon this code snippet which parses a string stored in buf with comma(,) as delimiter and store each substring into args, the question I'm having here is that I don't get why in the...
6
by: E. Robert Tisdale | last post by:
The following example shows how an Object Oriented C programmer might implement run-time polymorphism. The Circle "class" is "derived" from the Shape "class". Pointers to functions which actually...
3
by: RoSsIaCrIiLoIA | last post by:
I have rewrote the malloc() function of K&R2 chapter 8.7 typedef long Align; ^^^^ Here, should I write 'long', 'double' or 'long double'? I know that in my pc+compiler sizeof(long)=4,...
69
by: fieldfallow | last post by:
Hello all, Before stating my question, I should mention that I'm fairly new to C. Now, I attempted a small demo that prints out the values of C's numeric types, both uninitialised and after...
28
by: silvia.fama | last post by:
Hi! I'm using c language. I need to copy a long type value into a char string using a memcpy function: memcpy(string, (long *) value, len) this value will be then insert into a database. On...
13
by: Jeroen | last post by:
Hi all, I'm trying to implement a certain class but I have problems regarding the copy ctor. I'll try to explain this as good as possible and show what I tried thusfar. Because it's not about a...
8
by: d major | last post by:
I was very puzzled about the conversion between float and long, I cann't understand why a long val can convert to a float, as the below codes show: typedef unsigned long u_long; float val =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.