这是我得到的.
typedef struct SysInfo_P
{
int some_P_int
char some_P_char[10];
...
} SysInfo_P;
typedef struct SysInfo_S
{
int some_S_int
char some_S_char[10];
...
} SysInfo_S;
typedef struct Device
{
struct SomeData *data;
void *sysInfo;
...
} Device;
其 idea 是拥有一个基类设备,并在分配期间将其void
指针投射到适当的SysInfo_x
类.我总是使用void
个指针来为常见函数提供多功能性,但我似乎无法理解这一点……也许这是做不到的.
这是我徒劳的try ..在我的分配器里.
self->sysInfo = (SysInfo_S *)malloc(sizeof(*self->properties->sysInfo));
memset(self->sysInfo, 0, sizeof(*self->properties->sysInfo));