[Python-Dev] struct.pack inconsistencies between platforms (original) (raw)

Eli Bendersky eliben at gmail.com
Sun Feb 26 14:16:18 CET 2012


On Sun, Feb 26, 2012 at 15:09, Paul Moore <p.f.moore at gmail.com> wrote:

On 26 February 2012 12:34, Eli Bendersky <eliben at gmail.com> wrote: > On Sun, Feb 26, 2012 at 12:33, pmon mail <pmon.mail at gmail.com> wrote: >> 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:

As the OP points out, the documentation says that the "Standard Size" is 4 bytes (http://docs.python.org/library/struct.html). While "Standard Size" doesn't appear to be defined in the documentation, and the start of the previous section (7.3.2.1. Byte Order, Size, and Alignment) clearly states that C types are represented in native format by default, the documentation could probably do with some clarification. 7.2.3.1 says, shortly after the first table:

"

Native size and alignment are determined using the C compiler’s sizeofexpression. This is always combined with native byte order.

Standard size depends only on the format character; see the table in the Format Characters <http://docs.python.org/library/struct.html#format-characters>section. "

To me this appears to be a reasonable definition of what "standard size" is.

7.3.2.2 says before the size table:

"Format characters have the following meaning; the conversion between C and Python values should be obvious given their types. The ‘Standard size’ column refers to the size of the packed value in bytes when using standard size; that is, when the format string starts with one of '<', '>', '!' or '='. When using native size, the size of the packed value is platform-dependent."

Again, taken together with the previous quote, IMHO this defines the difference between standard and native sizes clearly. If you feel differently, feel free to open an issue suggesting a better explanation.

Eli -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20120226/e960efab/attachment.html>



More information about the Python-Dev mailing list