[Python-ideas] Exact integral types in struct

Guido van Rossum guido at python.org
Tue Mar 20 19:32:35 CET 2012

Using the '<' and '>' prefixes to the format string you can force
standard size and alignment. Do you have a specific bit of code in the
stdlib in mind that is incorrectly using native alignment?

On Tue, Mar 20, 2012 at 11:26 AM, Serhiy Storchaka <storchaka at gmail.com> wrote:
> The struct module works only with natural platform-specific integers. As a
> result, a lot of code in the standard library and third-party applications
> are forced either to rely on unreliable assumptions (short is always 2-byte,
> long is always 4-byte), which is not always true, either explicitly
> construct the integer from bytes (b[0]+(b[1]<<8)+(b[2]<<16)+...). I propose
> to introduce a special notation formats for signed and unsigned integers of
> arbitrary exact size (which is given a number preceded by the prefix). After
> that, eliminate the use of platform-specific formats when working with
> platform-independent data (such as zip, for example).
> Or maybe I'm behind, and the corresponding functions already exist, and the
> use of the struct module is only remnants?
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas

--Guido van Rossum (python.org/~guido)

More information about the Python-ideas mailing list