Mailing List Archive

[issue5145] struct.calcsize('cd') returns 16 instead of 9
New submission from bob gailer <bgailer@gmail.com>:

struct.calcsize('cd') returns 16 instead of 9

struct.calcsize('dc') returns 9 as expected

----------
components: Extension Modules
messages: 81085
nosy: bgailer
severity: normal
status: open
title: struct.calcsize('cd') returns 16 instead of 9
type: behavior
versions: Python 2.5

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5145>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue5145] struct.calcsize('cd') returns 16 instead of 9 [ In reply to ]
bob gailer <bgailer@gmail.com> added the comment:

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.

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5145>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue5145] struct.calcsize('cd') returns 16 instead of 9 [ In reply to ]
Changes by Antoine Pitrou <pitrou@free.fr>:


----------
assignee: -> georg.brandl
components: +Documentation -Extension Modules
nosy: +georg.brandl

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5145>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue5145] struct.calcsize('cd') returns 16 instead of 9 [ In reply to ]
Georg Brandl <georg@python.org> added the comment:

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?

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5145>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue5145] struct.calcsize('cd') returns 16 instead of 9 [ In reply to ]
STINNER Victor <victor.stinner@haypocalc.com> added the comment:

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

----------
nosy: +haypo

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5145>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com