#define offsetof(type, member) ((size_t)(&((type *)0)->member))
I am not understanding (&((type *)0)->member) what is this exactly telling me…..
here type may be a structure or something else??…
More specifically what is that 0 telling me here??
I break it down like this:
(type *)0– casting0to a pointer to type “type“. i.e. imagine for a minute that there’s an object of type “type” at memory address 0.->member– look into the object for the field calledmember.&– take the address of that.You could also write it like this:
But we’re cheating and using
0so that there’s no offset to take off at the end.