skyrock
New Member
I am migrating from ASM to C and but kind of confused with some examples I went through. As I understand, #define makes and only makes constant? But somehow i went through some rather complicated usage of defines which I can't understand. Can someone help explain what the last four #define tries to do?
Code:
/* eemap.h */
struct CFG {
char c;
int i;
long l;
double d;
};
struct CAL {
int scale;
int offset;
int slope;
};
struct LOG_ENTRY {
long time;
long meas;
};
typedef struct EE_MAP {
struct CFG cfg;
struct CAL cal;
struct LOG_ENTRY log[1024];
} EE_MAP;
#define EE_ADDR_CFG(mbr) (offsetof(EE_MAP, cfg) + offsetof(struct CFG, mbr))
#define EE_ADDR_CAL(mbr) (offsetof(EE_MAP, cal) + offsetof(struct CAL, mbr))
#define EE_ADDR_LOG() (offsetof(EE_MAP, log))
#define EE_ADDR_LOG_ENTRY(i) (EE_ADDR_LOG() + ((i) * sizeof(struct LOG_ENTRY)))
Last edited: