This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Offset to a member of a structure (relative to that structure)

I have a structure I would like to compute the offset to members within.

I've attempted this numerous ways all of which fail to generate a CONSTANT offset instead the compiler insists and create code for what is essentially the subtraction of 2 constants. (mutter) so

typedef unsigned short uint16_t;
#define SENSOR_TYPE_OFFSET              ((uint16_t)((char *)&ralph.constants.some_stuff.silly_putty) - (uint16_t)((char *)&ralph))


generates lots of cute code but not a constant offset to the member of the type ralph is. So are there any suggestions of beating the compiler into doing what I want?
I would rather not compute the offsets by hand. I suppose I could add up the sizeof() for each member also but either one is kind of annoyingly messy and very ugly.

0