jepri has asked for the wisdom of the Perl Monks concerning the following question:

I'm using perl to build data structures for a C program (they get mmaped), and I find myself with the need to write 64-bit unsigned integers (I'm doing bit vectors, and I want C to use the built in long long type).

The documentation for pack doesn't mention native 64-bit types (except quads, which are not what I want).

Are there any plans for perl to include support for long longs, or will I have to write a XS module called "Bit::LongLong". And if I do, how do I get the packed representation through perl's print statement without it getting mangled? Will perl leave a string of bytes alone or will it try to interpret it?

____________________
Jeremy
I didn't believe in evil until I dated it.

Replies are listed 'Best First'.
Re: Perl printing long long types
by BrowserUk (Patriarch) on Jul 03, 2003 at 01:45 UTC

    'scuse my ignorance, but whats the difference between a "long long unsigned 64-bit value" and "An unsigned quad value"?

    From perlfunc:pack

    q A signed quad (64-bit) value. Q An unsigned quad value. (Quads are available only if your system supports 64-bit integer values _and_ if Perl has been compiled to support t +hose. Causes a fatal error otherwise.)

    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller


      Because it doesn't accept a single number as an argument? (It's for IP addresses)

      Plus, it isn't even compiled in on my system.

      ____________________
      Jeremy
      I didn't believe in evil until I dated it.

        Because it doesn't accept a single number as an argument? (It's for IP addresses)

        I don't understand what you mean by this?

        By way of recompense for my lack of understanding, you might find this bit from the 5.8 INSTALL doc interesting/useful?

        =head2 64 bit support.

        If your platform does not have 64 bits natively, but can simulate them with compiler flags and/or C<long long> or C<int64_t>, you can build a perl that uses 64 bits.

        There are actually two modes of 64-bitness: the first one is achieved using Configure -Duse64bitint and the second one using Configure -Duse64bitall. The difference is that the first one is minimal and the second one maximal. The first works in more places than the second.

        The C<use64bitint> does only as much as is required to get 64-bit integers into Perl (this may mean, for example, using "long longs") while your memory may still be limited to 2 gigabytes (because your pointers could still be 32-bit). Note that the name C<64bitint> does not imply that your C compiler will be using 64-bit C<int>s (it might, but it doesn't have to): the C<use64bitint> means that you will be able to have 64 bits wide scalar values.

        The C<use64bitall> goes all the way by attempting to switch also integers (if it can), longs (and pointers) to being 64-bit. This may create an even more binary incompatible Perl than -Duse64bitint: the resulting executable may not run at all in a 32-bit box, or you may have to reboot/reconfigure/rebuild your operating system to be 64-bit aware.

        Which if I read it right, indicates that you can get 64-integers in perl even on 32-bit platforms as of 5.8.

        You would have to re-compile to get it of course.


        Examine what is said, not who speaks.
        "Efficiency is intelligent laziness." -David Dunham
        "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller


Re: Perl printing long long types
by jepri (Parson) on Jul 03, 2003 at 01:44 UTC
    Or I could just keep everything in "0010010111001" format and pack it with pack "b", $byte_string at the last moment. There goes any speed I thought I might get...

    ____________________
    Jeremy
    I didn't believe in evil until I dated it.