Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
checking if machine is 64-bit
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  11 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Suraj Kurapati  
View profile  
 More options Jul 28 2007, 1:42 pm
Newsgroups: comp.lang.ruby
From: Suraj Kurapati <s...@gna.org>
Date: Sun, 29 Jul 2007 02:42:46 +0900
Local: Sat, Jul 28 2007 1:42 pm
Subject: checking if machine is 64-bit
Hello,

I am checking if the machine is 64-bit by doing this:

  require 'rbconfig'
  is_machine_64_bit = ( Config::CONFIG["arch"] =~ /64/ )

Is there a better way?

Thanks.
--
Posted via http://www.ruby-forum.com/.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Fellinger  
View profile  
 More options Jul 28 2007, 3:03 pm
From: "Michael Fellinger" <m.fellin...@gmail.com>
Date: Sun, 29 Jul 2007 04:03:28 +0900
Local: Sat, Jul 28 2007 3:03 pm
Subject: Re: checking if machine is 64-bit
On 7/29/07, Suraj Kurapati <s...@gna.org> wrote:

> Hello,

> I am checking if the machine is 64-bit by doing this:

>   require 'rbconfig'
>   is_machine_64_bit = ( Config::CONFIG["arch"] =~ /64/ )

Config::CONFIG['arch']
# "x86_64-linux"

> Is there a better way?

Not that i know of.

^ manveru


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Daniel Berger  
View profile  
(1 user)  More options Jul 28 2007, 3:50 pm
From: Daniel Berger <djber...@gmail.com>
Date: Sun, 29 Jul 2007 04:50:01 +0900
Local: Sat, Jul 28 2007 3:50 pm
Subject: Re: checking if machine is 64-bit
On Jul 28, 11:42 am, Suraj Kurapati <s...@gna.org> wrote:

> Hello,

> I am checking if the machine is 64-bit by doing this:

>   require 'rbconfig'
>   is_machine_64_bit = ( Config::CONFIG["arch"] =~ /64/ )

> Is there a better way?

if (2**33).kind_of?(Bignum)
   # 32 bit
else
   # 64 bit
end

Might need some tweaking once the 128 bit operating systems show up...

Regards,

Dan


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Suraj Kurapati  
View profile  
(1 user)  More options Jul 28 2007, 6:31 pm
Newsgroups: comp.lang.ruby
From: Suraj Kurapati <s...@gna.org>
Date: Sun, 29 Jul 2007 07:31:35 +0900
Local: Sat, Jul 28 2007 6:31 pm
Subject: Re: checking if machine is 64-bit

Daniel Berger wrote:
> if (2**33).kind_of?(Bignum)
>    # 32 bit
> else
>    # 64 bit
> end

Excellent idea.  However, note that it takes 34 bits to represent 2**33,
and 33 bits to represent 2**32. Thus, we can get away with only checking
whether 2**32 is a Fixnum:

  is_machine_64_bit = (2 ** 32).is_a? Fixnum
--
Posted via http://www.ruby-forum.com/.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Suraj Kurapati  
View profile  
 More options Jul 28 2007, 6:40 pm
Newsgroups: comp.lang.ruby
From: Suraj Kurapati <s...@gna.org>
Date: Sun, 29 Jul 2007 07:40:11 +0900
Local: Sat, Jul 28 2007 6:40 pm
Subject: Re: checking if machine is 64-bit

Suraj Kurapati wrote:
>   is_machine_64_bit = (2 ** 32).is_a? Fixnum

Hmm, after reading the ri manpage for Fixnum, I found a better way:

  (-1.size) is 4 on a 32-bit machine and 8 on a 64-bit machine.
--
Posted via http://www.ruby-forum.com/.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Xeno Campanoli  
View profile  
 More options Jul 28 2007, 6:51 pm
From: Xeno Campanoli <xcampan...@gmail.com>
Date: Sun, 29 Jul 2007 07:51:19 +0900
Local: Sat, Jul 28 2007 6:51 pm
Subject: Re: checking if machine is 64-bit
Suraj Kurapati wrote:
> Suraj Kurapati wrote:
>>   is_machine_64_bit = (2 ** 32).is_a? Fixnum

> Hmm, after reading the ri manpage for Fixnum, I found a better way:

>   (-1.size) is 4 on a 32-bit machine and 8 on a 64-bit machine.

Aren't you gonna get Kernel information for 32 bit if it's a 32 bit
Kernel on a 64 bit machine?

--
The only sustainable organizing methods focus not on scale,
but on good design of the functional unit,
not on winning battles, but on preservation.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Lionel Bouton  
View profile  
 More options Jul 28 2007, 6:56 pm
From: Lionel Bouton <lionel-subscript...@bouton.name>
Date: Sun, 29 Jul 2007 07:56:17 +0900
Local: Sat, Jul 28 2007 6:56 pm
Subject: Re: checking if machine is 64-bit

Suraj Kurapati wrote:
> Suraj Kurapati wrote:

>>   is_machine_64_bit = (2 ** 32).is_a? Fixnum

> Hmm, after reading the ri manpage for Fixnum, I found a better way:

>   (-1.size) is 4 on a 32-bit machine and 8 on a 64-bit machine.

I don't know if it matters to you, but IIRC there are architectures with
different sizes for integers and memory addresses (64 bit integers with
32 bit addresses if memory serves).

Lionel.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Logan Capaldo  
View profile  
 More options Jul 28 2007, 7:30 pm
From: "Logan Capaldo" <logancapa...@gmail.com>
Date: Sun, 29 Jul 2007 08:30:05 +0900
Local: Sat, Jul 28 2007 7:30 pm
Subject: Re: checking if machine is 64-bit

On 7/28/07, Lionel Bouton <lionel-subscript...@bouton.name> wrote:

> Suraj Kurapati wrote:
> > Suraj Kurapati wrote:

> >>   is_machine_64_bit = (2 ** 32).is_a? Fixnum

> > Hmm, after reading the ri manpage for Fixnum, I found a better way:

> >   (-1.size) is 4 on a 32-bit machine and 8 on a 64-bit machine.

> I don't know if it matters to you, but IIRC there are architectures with
> different sizes for integers and memory addresses (64 bit integers with
> 32 bit addresses if memory serves).

MRI needs sizeof(long) == sizeof(void *)  (or it won't compile). MRI Fixnums
are longs.

Lionel.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nobuyoshi Nakada  
View profile  
 More options Jul 28 2007, 7:38 pm
From: Nobuyoshi Nakada <n...@ruby-lang.org>
Date: Sun, 29 Jul 2007 08:38:11 +0900
Local: Sat, Jul 28 2007 7:38 pm
Subject: Re: checking if machine is 64-bit
Hi,

At Sun, 29 Jul 2007 02:42:46 +0900,
Suraj Kurapati wrote in [ruby-talk:262297]:

> I am checking if the machine is 64-bit by doing this:

>   require 'rbconfig'
>   is_machine_64_bit = ( Config::CONFIG["arch"] =~ /64/ )

> Is there a better way?

Depends on the purpose.

If you are trying to compile an extension library:

  is_machine_64_bit = check_sizeof("int") == 64

  is_machine_64_bit = try_static_assert("sizeof int == 64")

or, better in C source(s):

  #if SIZEOF_VOIDP == 8

Otherwise, if you want to know the current running platform is
64bit:

  is_machine_64_bit = [0].pack("i!").size == 8

Note that all of the above check for the size of int.

--
Nobu Nakada


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Lloyd Linklater  
View profile  
 More options Jul 30 2007, 8:53 am
Newsgroups: comp.lang.ruby
From: Lloyd Linklater <ll...@2live4.com>
Date: Mon, 30 Jul 2007 21:53:06 +0900
Local: Mon, Jul 30 2007 8:53 am
Subject: Re: checking if machine is 64-bit

Suraj Kurapati wrote:
>   (-1.size) is 4 on a 32-bit machine and 8 on a 64-bit machine.

Very slick!  Nice find!

--
Posted via http://www.ruby-forum.com/.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
M. Edward (Ed) Borasky  
View profile  
 More options Jul 30 2007, 9:20 am
From: "M. Edward (Ed) Borasky" <zn...@cesmail.net>
Date: Mon, 30 Jul 2007 22:20:14 +0900
Local: Mon, Jul 30 2007 9:20 am
Subject: Re: checking if machine is 64-bit

Lloyd Linklater wrote:
> Suraj Kurapati wrote:
>>   (-1.size) is 4 on a 32-bit machine and 8 on a 64-bit machine.

> Very slick!  Nice find!

Is that portable to jRuby??

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google