Jump to content
  • Advertisement

Archived

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

Guest Anonymous Poster

Void Pointers

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

Advertisement
What compiler and what version are you using? Many compilers have minor iostream bugs, especially with reguards to pointers.
Also, if I might ask, why aren't you using a float* for the function in the first place (if the reason is tied to other areas of your program, it makes sense, but just wondering out of curiosity).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I'm not using float * for the function because I need to be able to pass anything to this function, not just arrays of floats.

I use Mingw32 (GNU Win32 compiler).

I've found that the problem is that the array of floats is going out of scope in my code, before the function which takes a void pointer is called. But I can't seem to fix this. myFunction in reality takes a structure, one of the properties of this structure is a (void *).

------------------
LoungePig
OpenGUI

Share this post


Link to post
Share on other sites
Use malloc() or new to create your array so it wont go out of scope. Youll need to keep track of it somewhere as you have to free() or delete it though.

-Geoff

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I have an array of floats which I pass to a function which takes a void pointer like so:

float myArray[2];

myArray[0] = 1.8f;
myArray[1] = 0.9f;

myFunction( (void *) myArray );

Then in myFunction I cast these back to a float array, and write the values to stdout, but I end up with stupid numbers that arent what I said in the first place:

void myFunction(void *param)
{
float *myArray = (float *) param;
cout << myArray[0] << " " << myArray[1] << endl;
}

Why is this happening?

Thanks

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!