[Israel.pm] pack vs. different architectures

Offer Kaye offer.kaye at gmail.com
Tue Feb 1 06:10:57 PST 2005


On Tue, 1 Feb 2005 14:29:19 +0200, Roman M. Parparov wrote:
> Hey, guys.
> 
> I am facing the following problem:
> I have to write a C structure into a binary file using a perl program.
> That file is later read by an external utility.
> The perl program runs on an Origin200 (IRIX64 nasa 6.4 02121744 IP27 mips)
> compiled using 'cc -32' (because of Oracle 7.3.4 present) - perl 5.8.5
> The external utility runs on a Pentium (Linux earth 2.4.22 i686)
> 
> Please note that the irix is a 64-bit machine.
> 

Off-hand, I would guess the problem is with differences in size (in
bytes) of data types and endianess, with regards to how pack works.
See the "perldoc -f pack" manpage for details. For example, this
sentence says:
               *       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. 

Don't give up hope, though - there's some good advice here:
http://perlmonks.thepen.com/224666.html

Note for example the sentence:
<quote>
If you are writing a program to read files whose layout is
architecture specific, use the 'n', 'N', 'v' and 'V' formats. This
way, you will know that you are interpreting the information correctly
no matter what architecture your program is running on.
</quote>

Regards,
-- 
Offer Kaye



More information about the Perl mailing list