[plt-scheme] how to tell 32/64bit platform?

From: Thomas Chust (chust at web.de)
Date: Wed Sep 30 16:15:01 EDT 2009

2009/9/30 Eli Barzilay <eli at barzilay.org>:
> [...]
> ((dynamic-require 'scheme/foreign 'compiler-sizeof) 'int)
> [...]

Hello,

unless PLT Scheme's notion of "compiler-sizeof" is incompatible with
common C compilers' notion of "sizeof", this is not going to be a
reliable indicator whether the platform has a 64bit userland. There
are definitely some examples of 64bit userlands that still have 32bit
default word size for integers and hence sizeof(int) == 4 in C --
usually because computations on the smaller datatype are still faster
or to save memory. If I recall correctly, all early AMD64 platforms
fall into that category.

It would probably be wiser to check the size of pointers instead using
something like

  (define platform-64bit?
    (= ((dynamic-require 'scheme/foreign 'compiler-sizeof) '*) 8))

All 64bit platforms I know of also have sizeof(long) == 8 in C, but
since the size of the address space is really the most relevant
discriminating factor between 32bit and 64bit platforms, checking the
size of pointers seems most logical to me.

Ciao,
Thomas


-- 
All these theories, diverse as they are, have two things in common: They
explain the observed facts, and they are completely and utterly wrong.
                               -- Terry Pratchett, "The Light Fantastic"


Posted on the users mailing list.