Logo

Programming-Idioms

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

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.

(defun detect-architecture ()
  (let ((arch (machine-type)))
    (cond ((equalp arch "X86-64") (f64))
          ((equalp arch "X86") (f32))
          (t "unknown"))))
if constexpr(sizeof(nullptr) == 8) {
  f64();
} else {
  f32();
}

This tests the size of a pointer.

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