Created
January 6, 2021 20:27
-
-
Save x1unix/015c56c44c2196f53af2badc04f4cbe4 to your computer and use it in GitHub Desktop.
Golang - detect bitness
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"unsafe" | |
) | |
func main() { | |
// way 1 | |
const is64Bit = uint64(^uintptr(0)) == ^uint64(0) | |
// way 2 - 64bit pointer has size of 8 | |
ptrSz := unsafe.Sizeof(unsafe.Pointer(nil)) | |
fmt.Println("is 64 bit:", is64Bit, ptrSz == 8) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment