- 论坛徽章:
- 0
|
let p is a pointer to an object of type __s_name.
the address of __s_member in the object is
&p->__s_member = p + offset, so if p equals 0,
then offset = &0->__s_member.
In the equation above, type consistency is violated
(0 is int not ptr, &(0->__s_member) is of type ptr, rather than size_t),
so we must add type cast in order to pass compiler's type checking.
After type cast is added, the above equation is as following
offset = (size_t)&(((__s_name *)0)->__s_member).
conclusion: the macro computes the offset of an struct member, and
should be mastered as an C idiom. |
|