Possible Duplicate:
Why does this C code work?
Why doesn't this code for finding the offset of a field in a struct give segfault ?
#define offset(structName,fieldName) (&((structName *)0)->fieldName)
Possible Duplicate:
Why does this C code work?
Why doesn't this code for finding the offset of a field in a struct give segfault ?
#define offset(structName,fieldName) (&((structName *)0)->fieldName)
Because it is not accessing any data. It's just computing an address. Try doing either of these operations:
foo = *offset(MyStruct, MyField);
*offset(MyStruct, MyField) = 1234;
And you'll see a beautiful SEGFAULT :-)