是否有任何标准方法来检查操作系统是 32 位还是 64 位? 我检查了运行时和操作系统包,但找不到。 http://play.golang.org/p/d6NywMDMcY
package main
import "fmt"
import "runtime"
func main() {
fmt.Println(runtime.GOOS, runtime.GOARCH)
}
最佳答案
32 位或 64 位操作系统是什么意思?例如,用于GOOS=nacl
的GOARCH=amd64p32
是amd64
64位指令,32位指针和32-位类型 int
和 uint
。
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
输出:
nacl amd64p32
32 32
和
linux amd64
64 64
关于go - 如何检查我的程序是为 32 位还是 64 位处理器编译的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25741841/