I have the following in C:
typedef struct {
short Whole;
unsigned short Frac;
} FirstStruct, FAR *pFirstStruct;
typedef struct {
char FirstArr[3];
FirstStruct SecondArr[3][3]
} SecStruct, FAR * pSecStruct;
I would like to do something similar in Python. Found this answer explaining how to use ctypes
for this purpose, but I am having problems with SecondArr[3][3]
. Here's the code in Python:
class FirstStruct(ctypes.Structure):
_pack_ = 2
_fields = [("Whole", ctypes.c_short),
("Fract", ctypes.c_ushort)]
class SecStruct(ctypes.Structure):
class _A(ctypes.Array):
_type_ = ctypes.c_char
_length_ = 3
class _B(ctypes.Array):
_type_ = FirstStruct
_length_ = 3
class _C(ctypes.Array):
_type_ = _B
_length_ = 3
_pack_ = 2
_fields = [("FirstArr", _A),
("SecondArr", _C)]
By doing that, Pylance complains that "_B" is not defined
, and I'm not completely sure it will work, nor if it is safe to mix two subclasses in that way to create a new C structure.
Is this the correct way of doing it even if Pylance complains about it, or is there any other way to convert the structure mentioned?