Can a Ruby program determine whether it's running on a 32-bit or64-bit system?

Discussion in 'Ruby' started by Eric Promislow, Sep 3, 2008.

  1. I can't go by RUBY_PLATFORM -- I'm setting up a new 32-bit Linux box,
    and RUBY_PLATFORM is set to "i686-linux".

    Or maybe this is a bug -- repaved machine, installed Fedora Core 9,
    downloaded and built a vanilla Ruby 1.8.6 -- but I see this on another
    32-bit Linux box as well (this one's a virtual host, but `cat /proc/
    cpuinfo`
    suggests it's 32-bit)

    If anyone's wondering, this is related to the Komodo debugger. The
    ruby-debug-base component is not 32/64-bit universal, so I need to
    put the 32-bit binary in one dir, the 64-bit one in another, and
    direct the client to the right spot.

    Thanks,
    Eric Promislow
    Eric Promislow, Sep 3, 2008
    #1
    1. Advertising

  2. Eric Promislow

    Jan Dvorak Guest

    Re: Can a Ruby program determine whether it's running on a 32-bit or 64-bit system?

    On Wednesday 03 September 2008 02:39:37 Eric Promislow wrote:
    > I can't go by RUBY_PLATFORM -- I'm setting up a new 32-bit Linux box,
    > and RUBY_PLATFORM is set to "i686-linux".

    Well, i?86 means it is 32bit.
    64-bit x86 system would have 'x86_64-linux'.

    Jan
    Jan Dvorak, Sep 3, 2008
    #2
    1. Advertising

  3. Re: Can a Ruby program determine whether it's running on a 32-bit or 64-bit system?

    Eric Promislow wrote:
    > Can a Ruby program determine whether
    > it's running on a 32-bit or 64-bit system?


    Yes. Look at the result of calling the 'size' method on a Fixnum; it
    will be 4 on 32-bit machines, and 8 on 64-bit machines.

    >> 0.size

    => 4
    --
    Posted via http://www.ruby-forum.com/.
    Suraj Kurapati, Sep 3, 2008
    #3
  4. Eric Promislow

    Pablo Q. Guest

    Re: Can a Ruby program determine whether it's running on a 32-bit or 64-bit system?

    [Note: parts of this message were removed to make it a legal post.]

    I got 4 on 64bit Windows Server. That doesn't mean that it depends if it was
    built on 64bit or 32bit, I mean ruby core.

    2008/9/2 Suraj Kurapati <>

    > Eric Promislow wrote:
    > > Can a Ruby program determine whether
    > > it's running on a 32-bit or 64-bit system?

    >
    > Yes. Look at the result of calling the 'size' method on a Fixnum; it
    > will be 4 on 32-bit machines, and 8 on 64-bit machines.
    >
    > >> 0.size

    > => 4
    > --
    > Posted via http://www.ruby-forum.com/.
    >
    >



    --
    Pablo Q.
    Pablo Q., Sep 3, 2008
    #4
  5. Eric Promislow

    F. Senault Guest

    Re: Can a Ruby program determine whether it's running on a 32-bit or 64-bit system?

    Le 3 septembre 2008 à 02:42, Eric Promislow a écrit :

    > I can't go by RUBY_PLATFORM -- I'm setting up a new 32-bit Linux box,
    > and RUBY_PLATFORM is set to "i686-linux".


    Pack has a support for native size :

    >> RUBY_PLATFORM

    => "i386-freebsd6"
    >> [ -1 ].pack('l!').length

    => 4

    While...

    >> RUBY_PLATFORM

    => "amd64-freebsd7"
    >> [ -1 ].pack('l!').length

    => 8

    (From the Pickaxe : 'Any of the directives "sSiIlL" may be followed by
    an underscore (_) or bang (!) to use the underlying platform's native
    size for the specified type')

    Fred
    --
    When I was a child I had a fever. My hands felt just like two balloons.
    Now I got that feeling once again.
    I can't explain, you would not understand. This is not how I am.
    I have become comfortably numb. (Pink Floyd, Comfortably Numb)
    F. Senault, Sep 4, 2008
    #5
  6. Re: Can a Ruby program determine whether it's running on a 32-bit or 64-bit system?

    Suraj Kurapati wrote:
    > Eric Promislow wrote:
    >> Can a Ruby program determine whether
    >> it's running on a 32-bit or 64-bit system?

    >
    > Yes. Look at the result of calling the 'size' method on a Fixnum; it
    > will be 4 on 32-bit machines, and 8 on 64-bit machines.
    >
    >>> 0.size

    > => 4


    On my 32 bit machine I get this:
    p 0.size
    => 8

    p [ -1 ].pack('l!').length
    => 4

    I am not sure why, but there it is, fyi.
    --
    Posted via http://www.ruby-forum.com/.
    Lloyd Linklater, Sep 4, 2008
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Sway
    Replies:
    1
    Views:
    388
    William Ryan
    Aug 30, 2003
  2. Ben Fidge
    Replies:
    1
    Views:
    407
    Patrick Steele [MVP]
    Jun 22, 2004
  3. Benjamin Hell
    Replies:
    4
    Views:
    234
    Adonis Vargas
    Nov 30, 2007
  4. Samuel
    Replies:
    2
    Views:
    107
  5. David Filmer
    Replies:
    14
    Views:
    186
    Peter J. Holzer
    Aug 8, 2010
Loading...

Share This Page