Double typecast in "offset" macro???

Christopher R Volpe volpe at underdog.crd.ge.com
Thu Jun 7 00:27:24 AEST 1990


In the "Answers to Frequently Asked Questions" document,
the structure offset macro is defined as follows:

#define offset(type,mem) ((size_t) (char *)&(((type *)0)->mem))

Now, the "&" operator yields a pointer to the type of "mem".
If you want to convert it to be of type "size_t", why must it
first be converted to "char *" ??  What's wrong with the following:

#define offset(type,mem) ((size_t) &(((type *)0)->mem))

Thanks,
Chris



More information about the Comp.lang.c mailing list