Advertisement Jump to content
Sign in to follow this  
Mantear

Assigning a value (with a poitner twist)

This topic is 4881 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

Greetings, I've come across very odd behavior when assigning a value to a variable, and was hoping someone here might have some insight. Here's the scenario: I've got an array of int pointers, pointed to by "int** ppValues". The the first twist is that I need to be able to store both ints and floats within the same array. It's not really a problem, just requires some casting and makes the code somewhat... ugly. The problem occurs when I go to assign the value pointed to by a pointer in the array. Here's the line that's causing the odd behavior:
*((float*)ppValues[index]) = <float value>;
In the setup I have now, the array of pointers has a size of 3. When the line above is executed, the value pointed to by all 3 pointers in the array now points to a value of <float value>. It also seems to be independant of what 'index' is set to. How is this possible? I'm using MSVS 6.0.

Share this post


Link to post
Share on other sites
Advertisement
Are you sure that they're actually pointing to separate addresses?

You know, unions can make this kind of thing a lot easier..

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!