I have been looking tor sources, and i found a macro which is defined like so :
#define STRUCT_OFFSET(tp, member) \
((off_t) (((char*)&((tp*)0)->member)-(char*)0))
I looked up the off_t
and it is just typedef for long
, so it is the basic length of the pointer variable in the end. But what with this conversion?
((char*)&((tp*)0)
What does this even suppose to mean, why is there a zero? Also how does this part even works out (char*)0
, casting a zero (NULL) to the pointer to (NULL)? Suppose it if i do without a macro, i cant just do someting like int offset = &MyStruct::some_member;
Is this possible to do without macro?