Re: offsetof




luke wrote:
> hi all,
> i have another question.
> I've read the FAQ regarding my former question (sizeof struct and
> union) and in question 2.14 it talks about offset macro.
>
> #define offsetof(type, mem) ((size_t) \
> ((char *)&((type *)0)->mem - (char *)(type *)0))
>
> Can anyone explain me how it works.
> 1)I can't understand what "0" casted to (type *) means
> 2)Isn't the second menber of substraction "(char *)(type *)0" useless?

The second member of sustraction would be required on implementation
where the NULL pointer is *not* represented by all-bits-zero.
Probably, this is why offsetof macro is implementation specific.

.