Python ctype sizeof incorrect!
Posted Raffeale
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python ctype sizeof incorrect!相关的知识,希望对你有一定的参考价值。
- class
ctypes.
Structure
(*args, **kw) -
Abstract base class for structures in native byte order.
Concrete structure and union types must be created by subclassing one of these types, and at least define a
_fields_
class variable.ctypes
will create descriptors which allow reading and writing the fields by direct attribute accesses. These are the_fields_
-
A sequence defining the structure fields. The items must be 2-tuples or 3-tuples. The first item is the name of the field, the second item specifies the type of the field; it can be any ctypes data type.
For integer type fields like
c_int
, a third optional item can be given. It must be a small positive integer defining the bit width of the field.Field names must be unique within one structure or union. This is not checked, only one field can be accessed when names are repeated.
It is possible to define the
_fields_
class variable after the class statement that defines the Structure subclass, this allows creating data types that directly or indirectly reference themselves:class List(Structure): pass List._fields_ = [("pnext", POINTER(List)), ... ]
The
_fields_
class variable must, however, be defined before the type is first used (an instance is created,sizeof()
is called on it, and so on). Later assignments to the_fields_
class variable will raise an AttributeError.It is possible to defined sub-subclasses of structure types, they inherit the fields of the base class plus the
_fields_
defined in the sub-subclass, if any.
以上是关于Python ctype sizeof incorrect!的主要内容,如果未能解决你的问题,请参考以下文章