Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
program main
use iso_c_binding
implicit none
type(c_ptr) :: x
logical, parameter :: is_64 = c_sizeof(x) == 8
if (is_64) then
call f64
else
call f32
end if
end program main
This checks the size of the standard C interop pointer and deduces the system type from that.
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();
}
static if (size_t.sizeof == 4)
f32();
static if (size_t.sizeof == 8)
f64();
Using a static if condition, which is evaluated at compile-time.
version(X86)
f32();
version(X86_64)
f64();
version() is a compile-time condition.
switch(System.getProperty("sun.arch.data.model")) {
case "64":
f64();
break;
case "32":
f32();
break;
}
(defun detect-architecture ()
(let ((arch (machine-type)))
(cond ((equalp arch "X86-64") (f64))
((equalp arch "X86") (f32))
(t "unknown"))))
begin
{$ifdef cpu64}
f64;
{$endif}
{$ifdef cpu32}
f32;
{$endif}
end.
This is a compile time condition.
case 1.size
when 8 then f64
when 4 then f32
end
#[cfg(target_pointer_width = "64")]
f64();
#[cfg(target_pointer_width = "32")]
f32();