New submission from Jeremy Sanders <jer...@jeremysanders.net>:

The struct documentation at http://docs.python.org/library/struct.html says:

Standard size and alignment are as follows: no alignment is required for any 
type (so you have to use pad bytes); short is 2 bytes; int and long are 4 
bytes; long long (__int64 on Windows) is 8 bytes; float and double are 32-bit 
and 64-bit IEEE floating point numbers, respectively. _Bool is 1 byte.

long on linux x86-64 is not 4 bytes. It is 8 bytes long:

xpc1:~:$ python
Python 2.6.2 (r262:71600, Aug 21 2009, 12:23:57) 
[GCC 4.4.1 20090818 (Red Hat 4.4.1-6)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import struct
>>> struct.calcsize('L')
8
>>> struct.calcsize('l')
8

It is 4 bytes on i386, however. The documentation should say that long is 8 
bytes on linux x86-64.

Also, would it not be a good idea to add struct sizes with specific data sizes, 
e.g. 1 byte, 2 bytes, 4 bytes, 8 bytes, so that it is easier to write 
cross-platform code?

----------
components: Library (Lib)
messages: 100470
nosy: jeremysanders
severity: normal
status: open
title: struct documentation problem and suggestion to add fixed size formats
versions: Python 2.6

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue8069>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to