--- struct.rst.org 2010-06-12 23:19:36.000000000 +0200 +++ struct.rst 2010-06-13 00:39:05.000000000 +0200 @@ -21,7 +21,9 @@ order to maintain proper alignment for the C types involved; similarly, alignment is taken into account when unpacking. This behavior is chosen so that the bytes of a packed struct correspond exactly to the layout in memory - of the corresponding C struct. To omit pad bytes, use `standard` size and + of the corresponding C struct. To + handle platform independent data formats (such as file and network formats) with `standard` size or just + omit implicit pad bytes, specify alignment instead of `native` size and alignment: see :ref:`struct-alignment` for details. @@ -100,19 +102,19 @@ the byte order, size and alignment of the packed data, according to the following table: -+-----------+------------------------+--------------------+ -| Character | Byte order | Size and alignment | -+===========+========================+====================+ -| ``@`` | native | native | -+-----------+------------------------+--------------------+ -| ``=`` | native | standard | -+-----------+------------------------+--------------------+ -| ``<`` | little-endian | standard | -+-----------+------------------------+--------------------+ -| ``>`` | big-endian | standard | -+-----------+------------------------+--------------------+ -| ``!`` | network (= big-endian) | standard | -+-----------+------------------------+--------------------+ ++-----------+------------------------+----------+-----------+ +| Character | Byte order | Size | Alignment | ++===========+========================+==========+===========+ +| ``@`` | native | native | native | ++-----------+------------------------+----------+-----------+ +| ``=`` | native | standard | none | ++-----------+------------------------+----------+-----------+ +| ``<`` | little-endian | standard | none | ++-----------+------------------------+----------+-----------+ +| ``>`` | big-endian | standard | none | ++-----------+------------------------+----------+-----------+ +| ``!`` | network (= big-endian) | standard | none | ++-----------+------------------------+----------+-----------+ If the first character is not one of these, ``'@'`` is assumed. @@ -122,14 +124,10 @@ switchable endianness (bi-endian). Use ``sys.byteorder`` to check the endianness of your system. -Native size and alignment are determined using the C compiler's -``sizeof`` expression. This is always combined with native byte order. +Native size is determined using the C compiler's +``sizeof`` expression. This is always combined with native byte order and alignment. -Standard size and alignment are as follows: no alignment is required for any -type (so you have to use pad bytes); :ctype:`short` is 2 bytes; :ctype:`int` and -:ctype:`long` are 4 bytes; :ctype:`long long` (:ctype:`__int64` on Windows) is 8 -bytes; :ctype:`float` and :ctype:`double` are 32-bit and 64-bit IEEE floating -point numbers, respectively. :ctype:`_Bool` is 1 byte. +Standard size depends on the C type - see :ref:`format-characters`. Note the difference between ``'@'`` and ``'='``: both use native byte order, but the size and alignment of the latter is standardized.