[racket] Detecting 32/64-bit racket

From: Norman Gray (norman at astro.gla.ac.uk)
Date: Sat Oct 29 13:32:14 EDT 2011

Matthew, hello.

On 2011 Oct 29, at 17:43, Matthew Flatt wrote:

> 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?
>>>> [...]
>>> (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.

The following works:

(require (only-in ffi/unsafe ctype-sizeof _pointer))
(ctype-sizeof _pointer)

This is also more direct, since I suppose the question I'm actually asking, in asking 32/64, is "what size are the corresponding C pointers?"

>>  ;; 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)

In fact, what I was doing was something like

% racket -e '(if (eq? (expt 2 61) (expt 2 61)) "yes" "no")'

I'd guess that this isn't vulnerable to the same problem, but the ctype-sizeof method is surely preferable nonetheless.

Thanks for this.   All the best,

Norman


-- 
Norman Gray  :  http://nxg.me.uk
SUPA School of Physics and Astronomy, University of Glasgow, UK




Posted on the users mailing list.