Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Go, cannot convert type *int32 to type *int64

I’ve tried all the ways I can think of to convert type *int32 to type *int64 in Go, but no avail

https://go.dev/play/p/W2X0HEnn79q

Somebody help please.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You cannot convert an *int32 to *int64. One is a pointer pointing to a 4-byte location, the other is a pointer pointing to an 8-byte location.

You can convert the content of *int32 to int64, and get the address of that:

x:=int32(1) // x is int32
xPtr:=&x    // xPtr is *int32
y:=int64(*xPtr)  // y is int64
yPtr:=&y  // yPtr is *int64
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading