Is it possible to detect the system/processor architecture while the program is running (under windows and under linux) in c++?
On Windows, you may use __cpuid
. On Linux, you can open("/proc/cpuinfo")
and look through it.
Here is an example on Windows, based on the example in the MSDN page:
#include <intrin.h>
bool cpuSupports64()
{
int CPUInfo[4];
__cpuid(CPUInfo, 0);
return (CPUInfo[3] & 0x20000000) || false;
}