#define offsetof(TYPE, MEMBER) ((u32) & ((TYPE *)0)->MEMBER )
返回TYPE类型中,MEMBER成员变量相对type类型变量开头的地址偏移
例:
#define EVENT_INDEX_ADDR (EVENT_ADDR + offsetof(NVM_ExtEeprom_t, EventIndex))
#define EVENT_LOG_ADDR (EVENT_ADDR + offsetof(NVM_ExtEeprom_t, EventLogStore))
typedef struct
{
EventIndex_t EventIndex;
EventLogStore_t EventLogStore;
}NVM_ExtEeprom_t;
typedef struct
{
u16 CheckSum;
u16 Offset;
u16 Sum; //总记录数
}EventIndex_t;
typedef struct
{
EventLog_t EventBuf[500];
}EventLogStore_t;
typedef struct
{
u16 Index;
u16 UserId;
u8 EventId;
u8 HightYear;
DateTime_t DateTime;
}EventLog_t;