I have a struct
typedef struct
{
float m[4][4];
} myMatrix;
because of some need of the program I need to convert this to float*
I do it something like
if(! g_Fvar16)
g_Fvar16 = (float*)malloc(sizeof(float) * 16);
memcpy(&g_Fvar16, &struct_var, sizeof(float)*16);
return g_Fvar16;
this is one simple function. Now, from where I call this function, program crashes on accessing these values. g_Fvar16
is float*
sizeof(struct_var)
is 64 and so is the amount of memory allocated.
Can't I simply treat the copied memory as float*? I thougt this would be the fastest..
g_fVer16
is already a pointer, so you have to write
memcpy(g_Fvar16, &struct_var, sizeof(float)*16);
instead of
memcpy(&g_Fvar16, &struct_var, sizeof(float)*16);
(note the first &
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With