in reply to Re: Is there a 64-bit hex()?
in thread Is there a 64-bit hex()?

But the return value of hex() usually isn't an integer in the CPU-register sense!

And even when it is, plenty of languages can handle 64-bit integers on 32-bit hardware. There's no law that states that all variables must fit into a single CPU register. (How would strings ever work if that were the case?)

This kind of thing can be done portably. Therefore, it is legitimate to be puzzled about why Perl complains about it.

Replies are listed 'Best First'.
Re^3: Is there a 64-bit hex()?
by moritz (Cardinal) on Feb 10, 2009 at 10:44 UTC
    But the return value of hex() usually isn't an integer in the CPU-register sense!

    Right, it's an IV, which points to a native integer.

    And even when it is, plenty of languages can handle 64-bit integers on 32-bit hardware.

    With the appropriate amount of emulation, yes.

    Note that perl is written in C, and I don't think that C makes any guarantees for the availability of a 64 bit integer type. Many other language implementations "solve" this problem by ignoring platforms or compilers that don't do what they want, but perl's focus is usually stronger on portability.

    There's no law that states that all variables must fit into a single CPU register. (How would strings ever work if that were the case?)

    Sure there's no such law, but if they don't, they are generally not as efficient.

      Note that perl is written in C
      True.
      I don't think that C makes any guarantees for the availability of a 64 bit integer type.
      True. In fact, considering the age of C, I don't even think 32 bit integers are garanteed.
      Many other language implementations "solve" this problem by ignoring platforms or compilers that don't do what they want, but perl's focus is usually stronger on portability.
      ... true, but Perl can be compiled to have 64-bit integers even if the underlaying hardware is 32 bits. It's actually the C compiler that determines whether you can have 64 bit integers or not. And many modern C compilers, including gcc, allow for this. (But it has worked the other way around as well. About a dozen years ago, I worked on a 64-bit SUN platform, but the then version of gcc couldn't deal with 64 bits).

      Note also that even if your hardware is 32 bits, and you don't compile Perl to have 64 bit integers, your Perl integers still aren't limited to 32 bits. If an integer value exceeds 32 bits, Perl silently upgrades it to a float, and will give "integers" up to 64 bits. If the value exceeds about 53 bits, the "integers" aren't exact any more, they will have some losses in their least significant bits (which may mean that if you add 1 to such an integer, it doesn't change value).