Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: unpack and byteorder - tests fail on certain platforms

by davidrw (Prior)
on Jan 09, 2008 at 15:01 UTC ( [id://661370]=note: print w/replies, xml ) Need Help??


in reply to unpack and byteorder - tests fail on certain platforms

From pack:
The integer formats s, S , i , I , l , L , j , and J are inherently non-portable between processors and operating systems because they obey the native byteorder and endianness.
...
If you want portable packed integers you can either use the formats n , N , v , and V , or you can use the > and < modifiers. These modifiers are only available as of perl 5.9.2. See also perlport.
  • Comment on Re: unpack and byteorder - tests fail on certain platforms

Replies are listed 'Best First'.
Re^2: unpack and byteorder - tests fail on certain platforms
by halley (Prior) on Jan 11, 2008 at 17:47 UTC
    Agreed; a unit test of pack() and unpack() should not be concerned with the actual bytes of platform-dependent packings unless there is an independent, bug-free way of doing the packs and unpacks on that platform. The following would be good tests for the above formats:
    $x = pack($format, $original); ok($original == unpack($format, $x), 'reversible unpack'); $x = external_platform_pack($format, $original); ok($original == unpack($format, $x), 'unpack from platform-specific source'); $x = pack($format, $original); ok($original == external_platform_unpack($format, $x), 'pack to platform-specific source');
    Only the first one is devoid of platform-dependence. Of course, a diverse pool of $original value samples should be run.

    --
    [ e d @ h a l l e y . c c ]

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://661370]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-04-19 07:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found