Hello,
how can I achieve
long l = WHAT_EVER_MACRO (-12.5); main() { printf("%X",l); }
resulting in output "0xC1480000" the binary representation of the float -12.5 . Without that MACRO the value is 0xFFFFFFF4 = -12 for integers .
Because of given circumstances in an existing project I have to store float values during initialization in long variables.
Is there any possibility?
Thanks in advance
Jürgen
tmp.ul = receive_ul(); //receive the binary representation of a double type
In my opinion, this is a very dangerous way to deal with union. In this case, you are interested in the binary representation of a double - but somebody else might copy-paste this innocent looking code expecting the actual value to be in integer form. Without checking the stored data type, this is a recipe for a bug.
"somebody else might copy-paste this innocent looking code expecting the actual value to be in integer form."
I think we have gone through this multiple times by now:
1) you are right, as always;
2) that's a risk you have to take, until you have figure out a way to outlaw stupidity.
it is just impossible to write fool-proof code. whatever you write, someone somewhere will have figured out a way to mis-use your code.
stupidity is without limit, remember that next time.