That's the Linux way to do it
union { int i; float f } u { .f = 1.23f };
int i = u.i;
Another way is a memcpy, which I believe is the most defined way to do type punning int i;
float f;
memcpy(&i, &f, 4);
But you also have to assume the size of those primitive types but that's pretty safe in modern C/C++.