I\'m looking for a piece of code that can tell me the offset of a field within a structure without allocating an instance of the structure.
IE: given
How about the standard offsetof() macro (in stddef.h)?
Edit: for people who might not have the offsetof() macro available for some reason, you can get the effect using something like:
#define OFFSETOF(type, field) ((unsigned long) &(((type *) 0)->field))