classification
Title: struct.calcsize('cd') returns 16 instead of 9
Type: behavior Stage:
Components: Documentation Versions: Python 2.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: bgailer, georg.brandl, vstinner
Priority: normal Keywords:

Created on 2009-02-03 18:53 by bgailer, last changed 2009-03-27 01:38 by vstinner. This issue is now closed.

Messages (5)
msg81085 - (view) Author: bob gailer (bgailer) Date: 2009-02-03 18:53
struct.calcsize('cd') returns 16 instead of 9

struct.calcsize('dc') returns 9 as expected
msg81089 - (view) Author: bob gailer (bgailer) Date: 2009-02-03 19:13
Someone pointed out that one must consider alignment. I had overlooked
that. It makes sense that a d is double-word aligned.

Perhaps the documentation should mention alignment.
msg81193 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-02-05 10:33
The docs have this sentence:

"""
By default, C numbers are represented in the machine's native format and
byte
order, and properly aligned by skipping pad bytes if necessary
(according to the
rules used by the C compiler).
"""

What would you suggest be added?
msg81197 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2009-02-05 10:46
The default endiand and alignment is "native". Using <, >, = or ! 
endian, the alignement is standard.

Python 3.1a0 (py3k:69105M, Feb  3 2009, 15:04:35)
>>> struct.calcsize('cd')
12
>>> struct.calcsize('=cd')
9
>>> struct.calcsize('<cd')
9
msg84249 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2009-03-27 01:38
Sorry, but I don't see this issue as a bug because it's related to 
memory alignment as explained in the documentation. 

I choose to close this issue. If you think that the documentation 
should be improved, please suggest an updated doc.
http://docs.python.org/library/struct.html#struct.calcsize
History
Date User Action Args
2009-03-27 01:38:34vstinnersetstatus: open -> closed
resolution: not a bug
messages: + msg84249
2009-02-05 10:46:52vstinnersetnosy: + vstinner
messages: + msg81197
2009-02-05 10:33:24georg.brandlsetmessages: + msg81193
2009-02-03 19:44:22pitrousetassignee: georg.brandl
components: + Documentation, - Extension Modules
nosy: + georg.brandl
2009-02-03 19:13:22bgailersetmessages: + msg81089
2009-02-03 18:53:42bgailercreate