Is there any real different between using an union between two types and a reinterpret_cast between two types, for example--
#include <iostream>
int main(){
union{
unsigned short *a;
float *b;
};
float value = 0.6f;
b = &value;
std::cout << *a << std::endl;
unsigned short *s;
float *f;
f = &value;
s = reinterpret_cast< unsigned short*>(f);
std::cout << *s << std::endl;
return 0;
}
--the results of the test are the same between the union and the reinterpret_cast but I would like to know if there is some kind of difference I should be aware of when using both.
Thank you!
-Alex