offsetof
John F Carr
jfc at athena.mit.edu
Tue Mar 5 04:28:46 AEST 1991
Two questions about offsetof.
1. Is the following legal?
struct foo { struct bar { int b;} a;};
offsetof (struct foo, a.b);
The X toolkit source code assumes that offsetof (struct foo, a.b) is legal.
The compiler I use disagrees. I think it is right, but I'm not sure.
2. On how many compilers does the following trick to emulate offsetof not work:
(int)&((struct foo*)0)->member
How many of those do not provide an offsetof macro?
(I know of only one compiler which doesn't like the version using a NULL
pointer (Metaware High C 1.4r for the IBM RT), and that compiler provides
an offsetof macro).
--
John Carr (jfc at athena.mit.edu)
More information about the Comp.lang.c
mailing list