//void** d is a parm to this function
double* dblData = (double*)malloc(sizeof(double));
void* varData=NULL;
*dblData = getDblValue(); //set dblData
varData = malloc(sizeof(double));
*((double*)varData) = *dblData;
*d = varData;
double* to void*? Doesn't seem to work?
Trying to cast from a double to a void*. My code works for int, but I can't get the double cast to fully work. Any ideas would be awesome.
]
So if you sub double with int, this works. So any idea what i'm doing wrong?
Cheers
[Edited by - _Sigma on October 5, 2006 9:17:21 PM]
Quote:Original post by _Sigma
Trying to cast from a double to a void*. My code works for int, but I can't get the double cast to fully work.
Define "doesn't fully work". Do you get a compiler error? Is it a run-time problem?
My appologies. It doesn't crash or what not, but it spews out a funny number when I recast the void* to double*. 6.7 turns into -32748126 (roughly).
I've tried to incorporate your code into a small test program.
*d = varData;
This line will not compile for me - you are dereferencing a "void *" pointer.
So, how are you using this? This prints 6.7 correctly for me:
EDIT: Probably the more important question is "what are you actually trying to acheive here?". This code seems very convoluted.
#include <stdio.h>double getDblValue(){ return 6.7;}void TestFunc(void ** d){ double* dblData = (double*)malloc(sizeof(double)); void* varData=NULL; *dblData = getDblValue(); //set dblData varData = malloc(sizeof(double)); *((double*)varData) = *dblData; *d = varData;}int main(){ void * pd; TestFunc(&pd); printf("%f\n", *(double *)pd); return 0;}
EDIT: Probably the more important question is "what are you actually trying to acheive here?". This code seems very convoluted.
Ooh nice! Thanks a ton! Seems to work fine now. I'd r++ you, but with your 1337 rating, i think that would be more of an insult!
Cheers m8
Cheers m8
Quote:Original post by _Sigmamaybe its not a bug in the above code, but a bug in the way you're printing out the value?
My appologies. It doesn't crash or what not, but it spews out a funny number when I recast the void* to double*. 6.7 turns into -32748126 (roughly).
I've found myself stuck on a bug for ages wondering WhyTF is this value garbage!!, oh wait, im using %d instead of %f...
Quote:Original post by PhilMortonQuote:Original post by _Sigmamaybe its not a bug in the above code, but a bug in the way you're printing out the value?
My appologies. It doesn't crash or what not, but it spews out a funny number when I recast the void* to double*. 6.7 turns into -32748126 (roughly).
I've found myself stuck on a bug for ages wondering WhyTF is this value garbage!!, oh wait, im using %d instead of %f...
Well it was that too :P But there was indeed a bug in the above code. =)
Quote:Original post by _Sigma
Ooh nice! Thanks a ton! Seems to work fine now. I'd r++ you, but with your 1337 rating, i think that would be more of an insult!
Cheers m8
OK, so the maximum rating you can have on these forums is 1337? Interesting... I was hoping to get above 2K someday, but I guess that would't be 1337. Is there some kind of 00ber1337 rating?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement