http://www.perlmonks.org?node_id=794508

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

Dear monks,

How can I unpack a 64 bit value? I've reffered the perlpacktut and used 'q'. But it's reporting the error as follows,

Invalid type 'q' in pack at unpack_msg.pl line 196.

Replies are listed 'Best First'.
Re: Unpack 64 bit value
by Utilitarian (Vicar) on Sep 10, 2009 at 08:45 UTC
    q and Q require that your system support 64 bit ints.
    You may have to work around this limitation if you are on a 32 bit platform. tye produced an interesting 64-bit unpack here
Re: Unpack 64 bit value
by almut (Canon) on Sep 10, 2009 at 08:37 UTC

    From perldoc -f 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 thos +e. Causes a fatal error otherwise.)
Re: Unpack 64 bit value
by salva (Canon) on Sep 10, 2009 at 11:17 UTC

      Looking at the source, it looks like a very efficient implementation. It does native 64-bit arithmetic through overloaded operators. It doesn't use Math::BigInt or the like. (The number is stored in the NV slot of a blessed SV.)

      ...but native 64-bit arithmetic isn't supported by my compiler or it isn't enabled. Does any 32-bit compiler on a 32-bit platform have support for 64-bit arithmetic?

      It would be nice if it downgraded to using Math::BigInt if necessary.

        ...but native 64-bit arithmetic isn't supported by my compiler or it isn't enabled. Does any 32-bit compiler on a 32-bit platform have support for 64-bit arithmetic?

        I believe that C99 specifies support for the long long int (64 bits or bigger) type as mandatory, so any modern compiler aiming to be C99 compliant should have 64 bits support.

        My initial plan was to add a fallback mode able to handle 64 bit arithmetic with 32 bit ints (it shouldn't be too difficult) but until today nobody had asked for it so it just remained undone...

        Can you give me the details of your system, OS, compiler, etc? are you sure it doesn't support 64 bit integers in any way?

A reply falls below the community's threshold of quality. You may see it by logging in.