Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Enfekted

Typecasting pointers doesn't just copy values?

This topic is 5273 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Wow, am I ever confused. I''m writing a compiler for a custom syntax and I ran into an interesting phenominon that I find incredably odd. I have a variable that is pointing to memory dynamically allocated using Kernel32.dll''s HeapAlloc(). When I typecast the pointer to another variable the new variable points to a different location in memory. Why does it do that?
void *pValue = HeapAlloc(ph, HEAP_ZERO_MEMORY, size );
// pValue == 0x04a4295c


char *pCharValue = (char*)pValue;
// pCharValue == 0x00173C83


// Shouldn''t pValue == pCharValue like it would if I were to do the same thing in C++?

Share this post


Link to post
Share on other sites
Advertisement
How did you determine these memory addresses?

pValue == 0x04a4295c
pCharValue == 0x00173C83

Sounds like those are the actual address of the pointers, not what they point to.

Kuphryn

Share this post


Link to post
Share on other sites
i suggest to use new and delete for heap-allocation

addition: they cant be the adress of the pointer, bc then he had to give pCharValue the address of pValue (would be pCharValue = (char*)&pValue )

[edited by - fooman on June 9, 2004 12:22:25 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by kuphryn
How did you determine these memory addresses?

pValue == 0x04a4295c
pCharValue == 0x00173C83

Sounds like those are the actual address of the pointers, not what they point to.

Kuphryn


I got the values from the Visual Studio Debugger

Share this post


Link to post
Share on other sites
Hmmm, Actually I think something weird is happening here.

This is a screenshot of the debugger reporting the values of pValue and pDstValue which should equal each other.



The Console.WriteLine() produces the following
pValue = 0x00176f68
pDstVal = 0x00176f68

But you can see in the above image that pValue is being reported as 0x04a4295c

Maybe its a bug in Microsoft Studio???

Share this post


Link to post
Share on other sites
I did step over the line. The break stopped the debugger just above where I cut off the screenshot. I even stepped through Memory.ReAlloc() which returned the 0x00176f68 value, but the debugger never updated pValue.

Weird... I never thought there'd be a bug in one of Microsoft's Products

[edited by - Enfekted on June 9, 2004 1:28:29 PM]

Share this post


Link to post
Share on other sites
as i was working on my radiysort, i recognized, that there is a bug... but not all hope is lost: the local variables window workes fine for me...

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!