Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
bgailer mannequin opened this issue Feb 3, 2009 · 5 comments
Closed

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

bgailer mannequin opened this issue Feb 3, 2009 · 5 comments
Assignees
Labels
docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error

Comments

@bgailer
Copy link
Mannequin

bgailer mannequin commented Feb 3, 2009

BPO 5145
Nosy @birkenfeld, @vstinner

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/birkenfeld'
closed_at = <Date 2009-03-27.01:38:34.316>
created_at = <Date 2009-02-03.18:53:42.749>
labels = ['type-bug', 'invalid', 'docs']
title = "struct.calcsize('cd') returns 16 instead of 9"
updated_at = <Date 2009-03-27.01:38:34.256>
user = 'https://bugs.python.org/bgailer'

bugs.python.org fields:

activity = <Date 2009-03-27.01:38:34.256>
actor = 'vstinner'
assignee = 'georg.brandl'
closed = True
closed_date = <Date 2009-03-27.01:38:34.316>
closer = 'vstinner'
components = ['Documentation']
creation = <Date 2009-02-03.18:53:42.749>
creator = 'bgailer'
dependencies = []
files = []
hgrepos = []
issue_num = 5145
keywords = []
message_count = 5.0
messages = ['81085', '81089', '81193', '81197', '84249']
nosy_count = 3.0
nosy_names = ['georg.brandl', 'vstinner', 'bgailer']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue5145'
versions = ['Python 2.5']

@bgailer
Copy link
Mannequin Author

bgailer mannequin commented Feb 3, 2009

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

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

@bgailer bgailer mannequin added extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error labels Feb 3, 2009
@bgailer
Copy link
Mannequin Author

bgailer mannequin commented Feb 3, 2009

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.

@pitrou pitrou added docs Documentation in the Doc dir and removed extension-modules C modules in the Modules dir labels Feb 3, 2009
@birkenfeld
Copy link
Member

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?

@vstinner
Copy link
Member

vstinner commented Feb 5, 2009

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

@vstinner
Copy link
Member

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

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants