Void Pointers
There's no problem with your code. I tried it just to make sure, and it works fine.
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).
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).
October 17, 1999 10:39 PM
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
October 18, 1999 01:34 PM
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement