May 10, 2013 at 4:00pm
Let me remind you that:
A float's size is 32-bit
A char (unsigned too)'s size is 8-bit.
What you are doing is convert a POINTER TO float to a POINTER TO char.
Their size is equal, but you're doing it wrong.
1 2 3 4 5
|
float NumFloat = 2.f;
char * Pointer = (char *)(&NumFloat);
float * PointerFloat = (float *)(Pointer);
float DestFloat = *PointerFloat;
cout << DestFloat << endl;
|
This breaks C++'s type safety.
Be careful about that, don't play with it if you don't know pointers.
Your example featured a 4-byte memory leak and bad castings.
Last edited on May 10, 2013 at 4:00pm