[issue9989] ctypes bitfield problem

Daniel Stutzbach report at bugs.python.org
Wed Sep 29 20:34:54 CEST 2010


New submission from Daniel Stutzbach <daniel at stutzbachenterprises.com>:

The following program should print "0xdead" but instead prints "0x0".  This came from the following stackoverflow question:
http://stackoverflow.com/questions/3824617/python-structure-always-stuck-at-0-no-matter-what-value-you-assign-to-it

import ctypes
class Blah(ctypes.Structure):
    _fields_ = [("a", ctypes.c_uint64, 64),
                ("b", ctypes.c_uint16, 16),
                ("c", ctypes.c_uint8, 8),
                ("d", ctypes.c_uint8, 8)]

x = Blah(0xDEAD,0xBEEF,0x44,0x12)
print(hex(x.a))

----------
components: Library (Lib)
messages: 117637
nosy: stutzbach, theller
priority: normal
severity: normal
stage: unit test needed
status: open
title: ctypes bitfield problem
type: behavior
versions: Python 2.7, Python 3.1, Python 3.2

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


More information about the Python-bugs-list mailing list