Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • C++

Idiom #160 Detect if 32-bit or 64-bit architecture

Execute f32() if platform is 32-bit, or f64() if platform is 64-bit.
This can be either a compile-time condition (depending on target) or a runtime detection.

if constexpr(sizeof(nullptr) == 8) {
  f64();
} else {
  f32();
}

This tests the size of a pointer.
#ifdef __x86_64
f64();
#else
#ifdef _M_AMD64
f64();
#else
f32();
#endif
#endif

At compile time, compiler dependent.
if(Environment.Is64BitOperatingSystem)
{
    f64();
}
else
{
    f32();
}

New implementation...
< >
programming-idioms.org