[racket] Detecting 32/64-bit racket
At Sat, 29 Oct 2011 16:19:53 +0200, Niklas Larsson wrote:
> 2011/10/29 Thomas Chust <chust at web.de>:
> > 2011/10/29 Norman Gray <norman at astro.gla.ac.uk>:
> >> [...]
> >> Is there a recommended way to detect whether racket is a 32- or
> >> 64-bit executable?
> >> [...]
> >
> > Hello Norman,
> >
> > while I don't know whether this strategy is particularly
> > recommendable, I would suggest to use utilities from the FFI module:
> >
> > (require (only-in ffi/unsafe compiler-sizeof))
> >
> > (compiler-sizeof 'long) ; => 8 on a 64-bit system
> > ; => 4 on a 32-bit system
> >
>
> That doesn't work in all cases, sizeof(long) is 4 on 64-bit Windows.
Right -- use `_pointer' or `_intptr', and that's probably the strategy
I'd use.
At Sat, 29 Oct 2011 09:31:17 -0500, Robby Findler wrote:
> Another not so great way, in Racket, to tell if the current racket is
> built as a 64 bit or 32 bit executable (is that what you're wanting?)
>
> ;; 64bit? : -> boolean
> (define (64bit?) (eq? (expt 2 61) (expt 2 61)))
This is not a good approach. If you happen to compile on a 64-bit
machine, the compiler will end up constant-folding to
(define (64bit?) #t)
More generally, even on a 32-bit platform, I can imagine the compiler
one day "intern"ing the bignums that it generates through constant
folding.
This variant is reliable, though:
(define (64bit?) (fixnum? (expt 2 33)))
The compiler doesn't constant-fold `fixnum?' (though maybe it should
constant-fold when the argument is a fixnum on all platforms).