I developed bootstrap software to start my game. I did this with Go. It was especially important for me to be cross-platform. Also, I didn't want to divide the download links into two as x86 / x64. I wanted to handle everything in one output. That's why I had to compile to x86. When I do this, I cannot properly detect that the operating system is x86 or x64.
In a software compiled as x86, how can i properly detect operating system x86 or x64 (in Go).
This code is not correct when compiled as x86.
const is64Bit = uint64(^uintptr(0)) == ^uint64(0)
On Windows you can call IsWow64Process
to determine whether you are a 32-bit process running on a 64-bit OS. Note that it returns false if you are a 64-bit process running on a 64-bit OS, but if you have a 64-bit process running, then you know the OS is 64-bit or it wouldn't run.
Also note that 32-bit Windows is considered obsolete. Microsoft is already phasing out support for 32-bit Windows - they no longer want it to be installed on new computers.
On Linux you can call uname
and look at the machine
field. Here's a list of possible values. Note that most of them won't be compatible with your program, only i386
, i686
and x86_64
.