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

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?

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: 64 bit pointer to string
by BrowserUk (Patriarch) on Sep 06, 2003 at 11:35 UTC

    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!