[racket] runtime determining 32 vs 64 bit machine?

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Mon Dec 24 08:23:49 EST 2012

> On 12/24/12 12:24 AM, Danny Yoo wrote:
> > I'm currently looking at (system-type 'machine) to determine whether
> > I'm on a 32-bit vs 64-bit machine.  However, the strings I'm getting
> > are a bit too platform specific, and I'm resorting to matching the
> > string "64" somewhere in there.  Is there a nicer way to approach
> > this?

I don't think you want to use `(system-type 'machine)'. On Mac OS X,
information in `(system-type 'machine)' tells you whether the OS kernel
itself is running in 32-bit or 64-bit mode, which seems unlikely to be
what you're interested in.

Using `(system-library-subpath)' may be a better choice, since it
depends on the Racket build instead of the kernel. The `ffi/winapi'
library, for example, uses `(system-library-subpath #f)', because it's
trying to detect Win64 mode specifically.

I think probably we should add a 'word-size mode to `system-type', but
one of the reasons that there isn't already a direct predicate is that
it depends on why you want to distinguish a 32-bit from 64-bit
environment. Running in 32-bit mode or 64-bit mode currently implies
various things that could change in a future implementation, so maybe
there should be a more direct test for what you want. Or maybe
`(system-type 'word-size)' is what you need.


At Mon, 24 Dec 2012 00:34:31 -0500, David Van Horn wrote:
> Just a thought: (fixnum? (sub1 (expt 2 62)))

That's the right test if you're interested in the range of fixnums.

If you're interested in the size in bytes of a pointer for use with the
FFI, then

 (= 8 (ctype-sizeof _pointer))

would be better, although that expression and David's currently return
the same result.



Posted on the users mailing list.