[issue7355] Struct incorrectly compiles format strings

Mark Dickinson report at bugs.python.org
Thu Nov 19 20:10:22 CET 2009


Mark Dickinson <dickinsm at gmail.com> added the comment:

> Just for clarification, why does "ci" get padded but "ic" doesn't?

Because no padding is necessary in the second case:  both the integer and 
the character already start at a position that's a multiple of 4---the 
integer at position 0 and the character at position 4.

In the first case, without padding, the integer wouldn't start at a word 
boundary.

The aim is to make sure that the byte sequence output by struct.pack 
matches the layout of a corresponding C struct.  In the first case inter-
item padding is necessary to make that work, in the second it isn't.

You could argue that in the second case, Python should add trailing 
padding, but I'm not sure what the point would be.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7355>
_______________________________________


More information about the Python-bugs-list mailing list