Skip to content

Instantly share code, notes, and snippets.

@x1unix
Created January 6, 2021 20:27
Show Gist options
  • Save x1unix/015c56c44c2196f53af2badc04f4cbe4 to your computer and use it in GitHub Desktop.
Save x1unix/015c56c44c2196f53af2badc04f4cbe4 to your computer and use it in GitHub Desktop.
Golang - detect bitness
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