5

I've tried searching around but have come up with nothing: How can I determine the bits (32-bit or 64-bit) of my operating system with elisp?

On my 64-bit Linux machine, system-configuration evaluates to "x86_64-unknown-linux-gnu". I don't have a Windows 32-bit machine available, but could I potentially do

(defconst 32-bit (not (null (string-match "^i386-.*" system-configuration))))
(defconst 64-bit (not (null (string-match "^x86_64-.*" system-configuration))))

to detect the bits?

Edit: "Why would you want to know that?" I wanted to write an Elisp script that would download and run the appropriate version of an executable (32 or 64-bit) for the user's OS.

6
  • 1
    Wouldn't that only give you what architecture emacs was built on? You could be running a 32 bit emacs binary on a 64 bit system. I would assume the best way to do this would be (case system-type ...) with calls to a os specific tool that can determine architecture. Commented Apr 30, 2015 at 18:44
  • As was mentioned in other comments, you may need this for different purposes: to identify the size of the integer you can have in Emacs, to identify what other programs can receive as an input. If Emacs is 32-bit, but runs on a 64-bit machine, then knowing the system parameters won't help you to identify the size of an integer you can use. Also, you could count on integer overflow, say, (ash 1 31) to find out whether integers will overflow or not.
    – wvxvw
    Commented Apr 30, 2015 at 23:17
  • Re' your last edit: I don't think there is a cross-platform way to identify that. You would probably need to write OS-specific code for each case you care about and assume the system is the same as Emacs in other cases.
    – wvxvw
    Commented May 1, 2015 at 8:38
  • There's always /proc/cpuinfo.
    – Qudit
    Commented May 2, 2015 at 17:08
  • @Qudit No /proc on Windows. Commented May 3, 2015 at 6:47

4 Answers 4

3

This is quite hacky, and I'm not sure how reliable it is, but the value gc-cons-threshold depends on the underlying word size. It's 800000 on 64-bit systems, and 400000 on 32-bit systems.

(defconst 32-bit (= gc-cons-threshold 400000))
(defconst 64-bit (= gc-cons-threshold 800000))
2

The issue of 64/32 bit is just a part of the problem. Look at the larger problem: the user may be running Debian on a machine with an ARM processor, for example. Or she may be running a FreeBSD system. Also, under Windows, if the downloaded program will want to interact with Emacs, you'll probably want a different version depending on whether your Emacs is a Cygwin or a "native" build.

So, system-configuration is probably a good starting point, but you probably want to keep more of it than just the 64/32 bit info. You may actually want to keep the whole of system-configuration.

1

Given the use case (taken from a comment I wanted to write an Elisp script that would download and run the appropriate version of an executable (32 or 64-bit) for the user's OS.), the nicest way might be just to ask the user which version to download.

I'm not sure how you'd do that in elisp though

1
  • 1
    Using completing-read would be one way.
    – Qudit
    Commented May 3, 2015 at 17:15
0

Why would you want to now that?

You should be looking at the specific Emacs property/capability and not the hardware attributes.

E.g., most-positive-fixnum will tell you the size of the fixnum (incidentally, it will also tell you the word size: if it is bugger than 2^32, then you have a 64-bit CPU).

5
  • 4
    Calling out to external programs is probably a good enough reason
    – Squidly
    Commented Apr 30, 2015 at 16:29
  • what external program depends on that but cannot determine it itself?
    – sds
    Commented Apr 30, 2015 at 16:30
  • Choosing which program to call perhaps? Not everyone writes nice software - some people distributes different binaries under different names depending on 32/64 bit (see e.g. sqldeveloper)
    – Squidly
    Commented Apr 30, 2015 at 17:05
  • "Why would you want to know that?" I wanted to write an Elisp script that would download and run the appropriate version of an executable (32 or 64-bit) for the user's OS. Commented May 1, 2015 at 6:39
  • 64-bit Emacs cannot load 32-bit dll.
    – shynur
    Commented Jul 28, 2023 at 4:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.