[Python-Dev] struct.pack inconsistencies between platforms
Eli Bendersky
eliben at gmail.com
Sun Feb 26 13:34:24 CET 2012
On Sun, Feb 26, 2012 at 12:33, pmon mail <pmon.mail at gmail.com> wrote:
> Hi
>
> I have found myself in the following troubling situation.
>
> I'm running the following code on a Python 2.6.5 on Linux x86:
> Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
> [GCC 4.4.3] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import struct
> >>> len(struct.pack('L',0))
> 4
>
> Works as expected and documented (
> http://docs.python.org/library/struct.html).
>
> I'm running the same code on a MacPro (OS X 10.7.3) and I'm getting the
> following:
> Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05)
> [GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on
> darwin
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import struct
> >>> len(struct.pack('L',0))
> 8
>
> Documentation clearly states that the 'L' is a 4 byte integer.
>
> Is this a bug? I'm I missing something?
>
>
By default pack uses native size, not standard size. On a 64-bit machine:
>>> struct.pack('=L', 0)
'\x00\x00\x00\x00'
>>> struct.pack('L', 0)
'\x00\x00\x00\x00\x00\x00\x00\x00'
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20120226/c0309f5c/attachment.html>
More information about the Python-Dev
mailing list