How to check if my program is compiled for a 32- or 64-bit processor?

Is there a standard method for checking os 32 or 64 bit? I check the runtime and the os package but cannot find. http://play.golang.org/p/d6NywMDMcY

package main import "fmt" import "runtime" func main() { fmt.Println(runtime.GOOS, runtime.GOARCH) } 
+5
source share
2 answers

What do you mean by 32- or 64-bit OS? For example, GOARCH=amd64p32 , which is used for GOOS=nacl , is amd64 64-bit instructions with 32-bit pointers and 32-bit types int and uint s.

 package main import ( "fmt" "runtime" "strconv" ) func main() { const PtrSize = 32 << uintptr(^uintptr(0)>>63) fmt.Println(runtime.GOOS, runtime.GOARCH) fmt.Println(strconv.IntSize, PtrSize) } 

Playground: http://play.golang.org/p/TKnCA0gqsI

Conclusion:

 nacl amd64p32 32 32 

and

 linux amd64 64 64 
+6
source

You can use the unsafe package and calculate the pointer size (4 for 32 bits, 8 for 64 bits). Here is a working example: http://play.golang.org/p/MPap9KMD1y

-1
source

Source: https://habr.com/ru/post/1202139/


All Articles