in reply to Re: Re: 64 bit pointer to string
in thread 64 bit pointer to string

I really don't know anything about perl on 64-bit systems, but in the absence of any other responses...

What do you get if you do

my $x = 'hello world!'; my $px = pack 'P', $x; print length $px; # Ought to print '8' on a 64-bit system print unpack 'p', $px; # Should print 'Hello world!'

If that works, then Perl is packing the pointers correctly and you are 'using them wrong'. Sorry for such a vague diagnosis:)

If that doesn't work, then you maybe have discovered a bug in 64-bit perl and should raise it to p5p.


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
If I understand your problem, I can solve it! Of course, the same can be said for you.

Replies are listed 'Best First'.
Re: Re: Re: Re: 64 bit pointer to string
by Anonymous Monk on Sep 06, 2003 at 10:48 UTC
    Thanks for helping!
    Your code does the right thing and works. I think Perl5/OpenBSD 64bit does not like this pointer for its IOCTLs ...
    BTW this is the whole code:
    my $tocentry; my $toc=""; my $size=0; for(@tracks) { $toc.=" "; $size+=8; } if($os =~ /BSD/) { my $size_hi=int($size / 256); my $size_lo=$size & 255; if($BIG_ENDIAN) { # in 32bit: $tocentry=pack "CCCCP8l", $CDROM_MSF,0,$size_hi,$siz +e_lo,$toc; $tocentry=pack "CCCCP", $CDROM_MSF,0,$size_hi,$size_lo,$toc; # c +urrent version } else { $tocentry=pack "CCCCP8l", $CDROM_MSF,0,$size_lo,$size_hi,$toc; } ioctl(CD, $CDROMREADTOCENTRY, $tocentry) or die "cannot read track + info [$!] [$device]"; }
    Should I post in p5p?

      I wouldn't run off to p5p just yet...but that's me, you may get better and/or quicker answers there from someone who has a 64-bit system to play with. That said, of you go there, do so via the perl5porters@perl.com list rather than perlbug as what my snippet did prove is that this isn't a perlbug. Your just using it wrong:)

      One thing I notice is that you are attempting to pack a 16-bit numeric value by splitting it into two 8-bit values and using 'CC' and switching the bytes around to account for the endianess of the current system.

      A) I think that you are doing this wrongly.

      B) There is no need for you to do this sort of thing yourself. pack already has that smarts built-in, although it requires you to pass along some clue bats to enable it.

      pack has format specifiers 'n' and 'v' which will pack a 16-bit unsigned value from a number in a perl scalar, in either big-endian or little-endian format respectively.

      Also, you don't show where or how your $BIG_ENDIAN variable is being set, but you should take a look at the Config package which is a part of the standard distribution. In particular

      use Config; print $Config{ byteorder };

      will tell you the order of the bytes on the current system. It will probably return somethng like '12345678' or '78563412' on your system.

      Hope this helps.

      Update: You might also want to check out perlpacktut. It's about the best tutorial i've seen on pack. You may have a local copy, but it is fairly recent addition to the doc set,so the link above may help.


      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
      If I understand your problem, I can solve it! Of course, the same can be said for you.

        ok I may be using it wrongly with 64bit but it works flawlessly witth 32bit big and little endian. however it MAY be a perl bug considering the 'ioctl' command not the packing itself.

        ad A) it works ;-)
        ad B) I know that, but I had more problems with that than without
        I'm using:

        my $BIG_ENDIAN = unpack("h*", pack("s", 1)) =~ /01/; if($BIG_ENDIAN) { print STDERR "[big endian]\n" if $debug; } else { print STDERR "[little endian]\n" if $debug; }
        never failed so far.
        Thanks for the pointer to perlpacktut, I'll try a bit more before mailing anyone. But I definitely don't see why 64bit should not work like 32bit in this regard. Maybe I'm doing it wrong all the time, and it works on 32bit big/little endian by chance. Well I don't think that either ;-)

        Thanks!

Re: Re: Re: Re: 64 bit pointer to string
by Anonymous Monk on Sep 06, 2003 at 17:06 UTC
    that works on both openbsd/sparc64 and openbsd/alpha (both 64-bit systems, the first being big endian and the second being little endian). on the openbsd/i386 system it prints '4' and 'hello world!' as expected.