New submission from Steve Thompson <steve.f.thomp...@gmail.com>: Consider the following: import ctypes
class struct1( ctypes.Structure ): _pack_ = 1 _fields_ = [ ( "first", ctypes.c_uint8, 1 ), ( "second", ctypes.c_uint8, 1 ), ( "third", ctypes.c_uint8, 1 ), ( "fourth", ctypes.c_uint8, 1 ), ( "fifth", ctypes.c_uint8, 1 ), ( "pad", ctypes.c_uint16, 11 ), ] s1 = struct1() print ctypes.sizeof( s1 ) class struct2( ctypes.Structure ): _pack_ = 1 _fields_ = [ ( "first", ctypes.c_uint16, 1 ), ( "second", ctypes.c_uint16, 1 ), ( "third", ctypes.c_uint16, 1 ), ( "fourth", ctypes.c_uint16, 1 ), ( "fifth", ctypes.c_uint16, 1 ), ( "pad", ctypes.c_uint16, 11 ), ] s2 = struct2() print ctypes.sizeof( s2 ) The output is: 3 2 I'm generating python code from real c code. The compiler I'm using for the real c code packs both of these structures into two bytes. I need a way to make the first example work in python like the compiler without having to modify the source code. Is this possible? ---------- components: ctypes messages: 134393 nosy: Steve.Thompson priority: normal severity: normal status: open title: ctypes: Strange bitfield structure sizing issue versions: Python 2.6 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue11920> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com