go - 如何检查我的程序是为 32 位还是 64 位处理器编译的?

标签 go

是否有任何标准方法来检查操作系统是 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=naclGOARCH=amd64p32amd64 64位指令,32位指针和32-位类型 intuint

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/

相关文章:

for-loop - 遍历 channel 时出现错误 "too many variables in range"

go - 如何使用 Go 列出 Google Cloud Platform 上正在运行的实例

c++ - 分段堆栈如何工作

http - 在 Go 中打开基于 net/http 包的 html 文件

go - 带返回商和余数的除法

postgresql - SQL Prepare语句返回语法错误

go - 在 Go 的结构体中使用互斥锁

go - 构建 go 项目时,包 io/fs 不在 GOROOT 中

string - 在 Golang 中将 []interface 转换为 []string

Go 中的 HTTP header 名称