Go doesn't allow conversions between different types of pointers as it is inherently unsafe. But, if you still want to do it there is a
Pointer type in
unsafe package, which represents a pointer to an arbitrary type.
Any type of pointer can be converted to
unsafe.Pointer can be converted to any type of pointer as long as they have the same memory structure. This allows you to ignore the type system and interpret any type of data as data of any other type.
The exact equivalent of the C code in your example in Go would be:
var y int64
var x float64 = 1.2
y = *(*int64)(unsafe.Pointer(&x))
So first we convert
unsafe.Pointer, then convert that to
*int64 and finally dereference that to get an
int64 with the same bit structure as
Remember that there is a reason this is in
unsafe package. If you just want to know what the bits are, it's better to use
math.Float64bits(). But if for example you must use bitwise operators on
float then of course you have to convert it to
int (and back).